diff --git a/docs/picture.md b/docs/picture.md index 2c095474f3..bef5516e4e 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -336,6 +336,10 @@ R18 显示 | ------ | ---------- | ---------- | | pic | top | top-4h | +### 首页 + + + ## 绝对领域 ### 图集文章 diff --git a/lib/router.js b/lib/router.js index 8d4bc60800..885c193a35 100644 --- a/lib/router.js +++ b/lib/router.js @@ -209,6 +209,7 @@ router.get('/douban/celebrity/:id/:sort?', require('./routes/douban/celebrity.js router.get('/plainlaw/archives', require('./routes/plainlaw/archives.js')); // 煎蛋 +router.get('/jandan/article', require('./routes/jandan/article')); router.get('/jandan/:sub_model', require('./routes/jandan/pic')); // 喷嚏 diff --git a/lib/routes/jandan/article.js b/lib/routes/jandan/article.js new file mode 100644 index 0000000000..e8d4e2f341 --- /dev/null +++ b/lib/routes/jandan/article.js @@ -0,0 +1,61 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'http://jandan.net/', + }); + const $ = cheerio.load(response.data); + const list = $('div.list-post').get(); + + const items = await Promise.all( + list.map(async (li) => { + const $ = cheerio.load(li); + const link = $('a').first().attr('href'); + const title = $('a')[1].children[0].data; + const summary = $('div.indexs').clone().children().remove().end().text().trim(); + const author = $('div.time_s > a').first().text(); + let imgUrl = 'http:' + ($('img').attr('src') || $('img').attr('data-original')); + if (imgUrl.slice(-7,) === "!square") { + imgUrl = imgUrl.slice(0, -7); + } + + const [fullText, time] = await ctx.cache.tryGet(link, async () => { + const res = await got.get(link); + const $ = cheerio.load(res.data); + const [, year, month, day, hour, minute] = $('div.time_s') + .text() + .match(/.+@\s+(\d+)\.(\d+)\.(\d+)\s,\s(\d+):(\d+)/); + const time = new Date(`${year}-${month}-${day}T${hour}:${minute}:00+0800`).toUTCString(); + + const content = $('.f.post').first(); + content.find('h1').prevAll().remove().end().remove(); + content.find('div').nextAll().remove().end().remove(); + content.contents().each(function() { + if (this.nodeType === 8) { + $(this).remove(); + } + }); + const text = content.html().trim(); + + return [text, time]; + }); + const description = `

${summary}

${fullText}`; + + const single = { + title: title, + description: description, + link: link, + pubDate: time, + author: author + }; + return Promise.resolve(single); + })); + ctx.state.data = { + title: `煎蛋 - 首页`, + link: `http://jandan.net/`, + description: '煎蛋 - 地球上没有新鲜事', + item: items, + }; +};