feat: nautilus (topics) (#2459)
Co-authored-by: Enoch Ma <enoch@Enochs-Air.local>
This commit is contained in:
parent
c0f90d90e0
commit
57da1ea463
|
|
@ -10,6 +10,12 @@ pageClass: routes
|
|||
|
||||
<Route author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['排序方式, `best` 或 `newest`, 缺省 `best`']"/>
|
||||
|
||||
## Nautilus
|
||||
|
||||
### 话题
|
||||
|
||||
<Route author="emdoe" example=“/nautilus/topic/Art” path="/nautilus/topic/:tid" :paramsDesc=“[‘话题 id, 可在页面上方 TOPICS 栏目处找到']"/>
|
||||
|
||||
## UU 看书
|
||||
|
||||
### 小说更新
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue