Merge pull request #49 from knight42/github

支持订阅 GitHub Releases 更新
This commit is contained in:
DIYgod 2018-04-24 14:29:20 +08:00 committed by GitHub
commit 8fca0b6f1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 2 deletions

View File

@ -5,7 +5,8 @@
"sourceType": "module"
},
"env": {
"node": true
"node": true,
"es6": true
},
"rules": {
"no-console": 0,
@ -53,4 +54,4 @@
"quotes": [1, "single"],
"no-control-regex": 0
}
}
}

View File

@ -55,6 +55,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 北美票房榜
- 煎蛋
- 无聊图
- GitHub
- Releases
## 参与我们

View File

@ -70,4 +70,7 @@ router.get('/douban/movie/ustop', require('./routes/douban/ustop'));
// 煎蛋
router.get('/jandan/pic', require('./routes/jandan/pic'));
// GitHub
router.get('/github/release/:owner/:repo', require('./routes/github/release'));
module.exports = router;

48
routes/github/release.js Normal file
View File

@ -0,0 +1,48 @@
const axios = require('axios');
const art = require('art-template');
const path = require('path');
const config = require('../../config');
module.exports = async (ctx) => {
const owner = ctx.params.owner;
const repo = ctx.params.repo;
const response = await axios({
method: 'get',
url: `https://api.github.com/repos/${owner}/${repo}/releases`,
headers: {
'User-Agent': config.ua,
}
});
const data = await Promise.all(response.data.map(async (item) => {
let text = item.body;
if (text) {
// render github flavoured markdown
const resp = await axios({
method: 'post',
url: 'https://api.github.com/markdown',
data: {
text,
mode: 'gfm',
context: `${owner}/${repo}`,
},
});
text = resp.data;
}
return {
title: `${item.name || item.tag_name}`,
description: text,
pubDate: new Date(item.published_at).toUTCString(),
link: item.html_url,
};
}));
ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), {
title: `${owner}/${repo} 的 Releases`,
link: `https://github.com/${owner}/${repo}/releases`,
description: `${owner}/${repo} 的 Releases`,
lastBuildDate: new Date().toUTCString(),
item: data,
});
};