forked from DIYgod/RSSHub
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into wangjunyu
* master: fix: 数英网部分标题无法显示 (DIYgod#2184) 新增路由 语雀知识库 (DIYgod#2156) feat: 微博的description和image (DIYgod#2182)
- Loading branch information
Showing
6 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}) | ||
), | ||
}; | ||
}; |