diff --git a/docs/install/README.md b/docs/install/README.md index 7610afe033..c87683c04f 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -403,3 +403,7 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式 - bilibili 用户关注视频动态路由 - `BILIBILI_COOKIE_{uid}`: 对应 uid 的 b 站用户登录后的 Cookie 值,`{uid}` 替换为 uid,如 `BILIBILI_COOKIE_2267573`,获取方式:1. 打开 2. 打开控制台 3. 切换到 Network 面板 4. 刷新 5. 点击 dynamic_new 请求 6. 找到 Cookie + +- 语雀 全部路由: [注册地址](https://www.yuque.com/register) + + - `YUQUE_TOKEN`: 语雀 Token,[获取地址](https://www.yuque.com/settings/tokens) 。语雀接口做了访问频率限制,为保证正常访问建议配置 Token,详见[语雀开发者文档](https://www.yuque.com/yuque/developer/api#5b3a1535)。 diff --git a/docs/other.md b/docs/other.md index 915596702a..cc57bfe5fd 100644 --- a/docs/other.md +++ b/docs/other.md @@ -811,6 +811,18 @@ type 为 all 时,category 参数不支持 cost 和 free +## 语雀 + +### 知识库 + + + +| Node.js 专栏 | 阮一峰每周分享 | 语雀使用手册 | +| ------------ | -------------- | ------------ | +| 75258 | 102804 | 75257 | + + + ## 中国大学 MOOC(慕课) ### 最新 diff --git a/lib/config.js b/lib/config.js index 6d3d38ed3d..bf1a2d186f 100644 --- a/lib/config.js +++ b/lib/config.js @@ -64,7 +64,9 @@ module.exports = { bilibili: { cookies: bilibili_cookies, }, - + yuque: { + token: process.env.YUQUE_TOKEN, + }, puppeteerWSEndpoint: process.env.PUPPETEER_WS_ENDPOINT, loggerLevel: process.env.LOGGER_LEVEL || 'info', proxy: { diff --git a/lib/router.js b/lib/router.js index faae728989..1d93e00ee7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1303,6 +1303,9 @@ router.get('/curseforge/:gameid/:catagoryid/:projectid/files', require('./routes // 西南财经大学 router.get('/swufe/seie/:type?', require('./routes/universities/swufe/seie')); +// 语雀文档 +router.get('/yuque/doc/:repo_id', require('./routes/yuque/doc')); + // 飞地 router.get('/enclavebooks/category/:id?', require('./routes/enclavebooks/category')); diff --git a/lib/routes/yuque/doc.js b/lib/routes/yuque/doc.js new file mode 100644 index 0000000000..5024ebf467 --- /dev/null +++ b/lib/routes/yuque/doc.js @@ -0,0 +1,58 @@ +const axios = require('@/utils/axios'); +const config = require('@/config'); +// token通过process.env.YUQUE_TOKEN或者在config.js 配置 +const token = config.yuque.token; + +module.exports = async (ctx) => { + const { repo_id } = ctx.params; + const baseUrl = 'https://www.yuque.com'; + const repoUrl = `${baseUrl}/api/v2/repos/${repo_id}`; + const docsUrl = `${repoUrl}/docs`; + const fetchData = (url) => + axios({ + url, + method: 'get', + headers: { + 'X-Auth-Token': token, + }, + }); + + const repoDetail = await fetchData(repoUrl); + const { + name: repo, + user: { name }, + description, + } = repoDetail.data.data; + const docsDetail = await fetchData(docsUrl); + const docs = docsDetail.data.data; + + // 过滤掉草稿类型 + const publicDocs = docs.filter(({ status }) => status === 1); + ctx.state.data = { + title: `${name} / ${repo}`, + link: repoUrl, + description, + item: await Promise.all( + publicDocs.map(async (doc) => { + const item = { + title: doc.title, + description: doc.description, + pubDate: doc.created_at, + link: `${baseUrl}/${repo_id}/${doc.id}`, + }; + const key = `yuque${doc.id}`; + const value = await ctx.cache.get(key); + + if (value) { + item.description = value; + } else if (token) { + const docDetail = await fetchData(`${docsUrl}/${doc.id}`); + const { body_html } = docDetail.data.data; + item.description = body_html; + ctx.cache.set(key, item.description); + } + return Promise.resolve(item); + }) + ), + }; +};