diff --git a/docs/reading.md b/docs/reading.md index 9190134ef..25d14cc08 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -10,6 +10,12 @@ pageClass: routes +## Nautilus + +### 话题 + + + ## UU 看书 ### 小说更新 diff --git a/lib/router.js b/lib/router.js index e9249b06f..7f2f21c4c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -905,6 +905,9 @@ router.get('/coolbuy/newest', require('./routes/coolbuy/newest')); router.get('/nga/forum/:fid', require('./routes/nga/forum')); router.get('/nga/post/:tid', require('./routes/nga/post')); +// Nautilus +router.get('/nautilus/topic/:tid', require('./routes/nautilus/topics')); + // JavBus router.get('/javbus/home', require('./routes/javbus/home')); router.get('/javbus/genre/:gid', require('./routes/javbus/genre')); diff --git a/lib/routes/nautilus/topics.js b/lib/routes/nautilus/topics.js new file mode 100644 index 000000000..8046eda3a --- /dev/null +++ b/lib/routes/nautilus/topics.js @@ -0,0 +1,41 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const url = `http://nautil.us/term/f/${ctx.params.tid}`; + + const res = await got.get(url); + const $ = cheerio.load(res.data); + const list = $('article.search-result').get(); + + const out = await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + const title = $('h3 > a').text(); + const partial = $('h3 > a').attr('href'); + const address = `http://nautil.us${partial}`; + const cache = await ctx.cache.get(address); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const res = await got.get(address); + const capture = cheerio.load(res.data); + capture('div.reco').remove(); + const banner = capture('div.banner').html(); + const contents = banner + capture('div.page-content').html(); + const single = { + title, + description: contents, + link: address, + guid: address, + }; + ctx.cache.set(address, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + ctx.state.data = { + title: 'Nautilus | ' + $('title').text(), + link: url, + item: out, + }; +};