新增路由 语雀知识库 (#2156)

* feat: 新增语雀知识库

* fix: 更新语雀知识库文档

* prettier

* 代码重构 不变内容使用缓存

* 多余修改撤回

* prettier docs/install/README.md

* 语雀配置token文档补充
This commit is contained in:
aha2mao
2019-05-20 17:02:09 +08:00
committed by DIYgod
parent eb97769a2b
commit ac872e6476
5 changed files with 80 additions and 1 deletions

View File

@@ -403,3 +403,7 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式
- bilibili 用户关注视频动态路由
- `BILIBILI_COOKIE_{uid}`: 对应 uid 的 b 站用户登录后的 Cookie 值,`{uid}` 替换为 uid`BILIBILI_COOKIE_2267573`获取方式1. 打开 <https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=0&type=8> 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)。

View File

@@ -811,6 +811,18 @@ type 为 all 时category 参数不支持 cost 和 free
<Route author="xyqfer" example="/oilprice/shanghai" path="/oilprice/:area" :paramsDesc="['地区拼音,详见[成品油价格网](http://oil.usd-cny.com/)']"/>
## 语雀
### 知识库
<Route author="aha2mao" example="/yuque/doc/75258" path="/yuque/doc/:repo_id" :paramsDesc="['仓库id可在对应知识库主页的`/api/books/${repo_id}/docs`请求里找到']">
| Node.js 专栏 | 阮一峰每周分享 | 语雀使用手册 |
| ------------ | -------------- | ------------ |
| 75258 | 102804 | 75257 |
</Route>
## 中国大学 MOOC(慕课)
### 最新

View File

@@ -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: {

View File

@@ -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'));

58
lib/routes/yuque/doc.js Normal file
View File

@@ -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);
})
),
};
};