diff --git a/docs/README.md b/docs/README.md index 388ed5c37..c9305c083 100644 --- a/docs/README.md +++ b/docs/README.md @@ -263,6 +263,14 @@ s 参数: id,用户 id,可在用户主页 URL 中找到 +#### 专栏 + +举例: https://rss.now.sh/zhihu/zhuanlan/googledevelopers + +路由: `/zhihu/zhuanlan/:id` + +参数: id,专栏 id,可在专栏主页 URL 中找到 + ### 自如 #### 房源 diff --git a/package.json b/package.json index e25132f1a..7f452b251 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "koa-router": "7.4.0", "lru-cache": "4.1.2", "path-to-regexp": "2.2.0", + "phantom": "^4.0.12", "readall": "1.0.0", "winston": "3.0.0-rc3" } diff --git a/router.js b/router.js index 32afeb221..21e0bca79 100644 --- a/router.js +++ b/router.js @@ -45,6 +45,7 @@ router.get('/jianshu/user/:id', require('./routes/jianshu/user')); // // 知乎 router.get('/zhihu/collection/:id', require('./routes/zhihu/collection')); router.get('/zhihu/people/activities/:id', require('./routes/zhihu/activities')); +router.get('/zhihu/zhuanlan/:id', require('./routes/zhihu/zhuanlan')); // // 贴吧 router.get('/tieba/forum/:kw', require('./routes/tieba/forum')); diff --git a/routes/zhihu/zhuanlan.js b/routes/zhihu/zhuanlan.js new file mode 100644 index 000000000..a04b42241 --- /dev/null +++ b/routes/zhihu/zhuanlan.js @@ -0,0 +1,43 @@ +const axios = require('axios'); +const art = require('art-template'); +const path = require('path'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const listRes = await axios({ + method: 'get', + url: `https://zhuanlan.zhihu.com/api/columns/${id}/posts?limit=20`, + headers: { + 'User-Agent': config.ua, + 'Referer': `https://zhuanlan.zhihu.com/${id}`, + } + }); + const infoRes = await axios({ + method: 'get', + url: `https://zhuanlan.zhihu.com/api/columns/${id}`, + headers: { + 'User-Agent': config.ua, + 'Referer': `https://zhuanlan.zhihu.com/${id}`, + } + }); + + const list = listRes.data; + const info = infoRes.data; + + ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), { + title: `知乎专栏-${info.name}`, + link: `https://zhuanlan.zhihu.com/${id}`, + description: info.description, + lastBuildDate: new Date().toUTCString(), + item: list.map((item) => { + return { + title: item.title, + description: item.content, + pubDate: new Date(item.publishedTime).toUTCString(), + link: `https://zhuanlan.zhihu.com${item.url}` + }; + }), + }); +}; \ No newline at end of file