From eb97769a2b4bc9438bb2a012d46e3f2d0c7def78 Mon Sep 17 00:00:00 2001 From: Wang Junyu Date: Mon, 20 May 2019 14:51:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=BE=AE=E5=8D=9A=E7=9A=84descript?= =?UTF-8?q?ion=E5=92=8Cimage=20(#2182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/weibo/user.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/routes/weibo/user.js b/lib/routes/weibo/user.js index 75a2a05b60b8c..47f9ac81b31cb 100644 --- a/lib/routes/weibo/user.js +++ b/lib/routes/weibo/user.js @@ -13,6 +13,8 @@ module.exports = async (ctx) => { }, }); const name = containerResponse.data.data.userInfo.screen_name; + const description = containerResponse.data.data.userInfo.description; + const profileImageUrl = containerResponse.data.data.userInfo.profile_image_url; const containerid = containerResponse.data.data.tabsInfo.tabs[1].containerid; const response = await axios({ @@ -29,7 +31,8 @@ module.exports = async (ctx) => { ctx.state.data = { title: `${name}的微博`, link: `http://weibo.com/${uid}/`, - description: `${name}的微博`, + description: description, + image: profileImageUrl, item: response.data.data.cards .filter((item) => item.mblog && !item.mblog.isTop) .map((item) => { From ac872e647642cd93d2db1b9b51e588a9ac71ec8d Mon Sep 17 00:00:00 2001 From: aha2mao Date: Mon, 20 May 2019 17:02:09 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B7=AF=E7=94=B1=20?= =?UTF-8?q?=E8=AF=AD=E9=9B=80=E7=9F=A5=E8=AF=86=E5=BA=93=20(#2156)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 新增语雀知识库 * fix: 更新语雀知识库文档 * prettier * 代码重构 不变内容使用缓存 * 多余修改撤回 * prettier docs/install/README.md * 语雀配置token文档补充 --- docs/install/README.md | 4 +++ docs/other.md | 12 +++++++++ lib/config.js | 4 ++- lib/router.js | 3 +++ lib/routes/yuque/doc.js | 58 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 lib/routes/yuque/doc.js diff --git a/docs/install/README.md b/docs/install/README.md index 7610afe033584..c87683c04f7e0 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 915596702a083..cc57bfe5fde62 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 6d3d38ed3d3e7..bf1a2d186fd44 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 faae728989949..1d93e00ee7c34 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 0000000000000..5024ebf467dd1 --- /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); + }) + ), + }; +}; From 2097f57597787bb039bdaf4fc77b251e8d3386a5 Mon Sep 17 00:00:00 2001 From: Fan Shen <1370275510@qq.com> Date: Mon, 20 May 2019 17:24:06 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E6=95=B0=E8=8B=B1=E7=BD=91=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=A0=87=E9=A2=98=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=20(#2184)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/digitaling/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/digitaling/index.js b/lib/routes/digitaling/index.js index 6f83f99fb0739..b0a3be34c6a69 100644 --- a/lib/routes/digitaling/index.js +++ b/lib/routes/digitaling/index.js @@ -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(),