Skip to content

Commit

Permalink
Merge branch 'master' into wangjunyu
Browse files Browse the repository at this point in the history
* master:
  fix: 数英网部分标题无法显示 (DIYgod#2184)
  新增路由 语雀知识库 (DIYgod#2156)
  feat: 微博的description和image (DIYgod#2182)
  • Loading branch information
iplusx committed May 21, 2019
2 parents d9a5459 + 6fa6fe5 commit 9788281
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/install/README.md
Expand Up @@ -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)
12 changes: 12 additions & 0 deletions docs/other.md
Expand Up @@ -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(慕课)

### 最新
Expand Down
4 changes: 3 additions & 1 deletion lib/config.js
Expand Up @@ -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: {
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Expand Up @@ -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'));

Expand Down
2 changes: 1 addition & 1 deletion lib/routes/digitaling/index.js
Expand Up @@ -22,7 +22,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(res.data);

const item = {
title: $('.project_title h2').text(),
title: $('.clearfix h2').text(),
author: $('#avatar_by')
.find('a')
.text(),
Expand Down
58 changes: 58 additions & 0 deletions 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);
})
),
};
};

0 comments on commit 9788281

Please sign in to comment.