diff --git a/docs/reading.md b/docs/reading.md index 9e601f4f4..b412b4a5d 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -32,6 +32,16 @@ pageClass: routes +### 思想库(专栏) + + + +| 论文 | 时评 | 随笔 | 演讲 | 访谈 | 著作 | 读书 | 史论 | 译作 | 诗歌 | 书信 | 科学 | +| ---- | ---- | ----- | ---- | ----- | ------ | ----- | ------ | ----- | ----- | ------ | ----- | +| lunw | ship | shuib | yanj | fangt | zhuanz | dushu | shilun | yizuo | shige | shuxin | kexue | + + + ## 爱下电子书 ### 最新章节 diff --git a/lib/router.js b/lib/router.js index 8a9df3e56..2d0f2ca18 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1259,6 +1259,7 @@ router.get('/whalegogo/portal/:type_id/:tagid?', require('./routes/whalegogo/por // 爱思想 router.get('/aisixiang/column/:id', require('./routes/aisixiang/column')); router.get('/aisixiang/ranking/:type?/:range?', require('./routes/aisixiang/ranking')); +router.get('/aisixiang/thinktank/:name/:type?', require('./routes/aisixiang/thinktank')); // Hacker News router.get('/hackernews/:section/:type?', require('./routes/hackernews/story')); diff --git a/lib/routes/aisixiang/thinktank.js b/lib/routes/aisixiang/thinktank.js new file mode 100644 index 000000000..24adcffdc --- /dev/null +++ b/lib/routes/aisixiang/thinktank.js @@ -0,0 +1,40 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const util = require('./utils'); + +module.exports = async (ctx) => { + const { name, type = 'lunw' } = ctx.params; + + const host = `http://www.aisixiang.com/thinktank/${name}.html`; + + const response = await got.get(host, { + responseType: 'buffer', + }); + response.data = iconv.decode(response.data, 'gbk'); + + const $ = cheerio.load(response.data); + + const tds = $('td > img').filter(function () { + return $(this).attr('src') === `images/${type}.gif`; + }); + if (tds.length === 0) { + throw `Type Not Found - ${type}`; + } + + const list = tds.parent().next().find('a').slice(0, 5).get(); + + const items = await Promise.all( + list.map(async (e) => { + const link = $(e).attr('href'); + return await ctx.cache.tryGet(link, async () => await util.ProcessFeed(link)); + }) + ); + + ctx.state.data = { + title: $('title').text(), + link: host, + description: $('meta[name="description"]').attr('content'), + item: items, + }; +};