diff --git a/docs/README.md b/docs/README.md
index 286c079a55..07afffe722 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -994,3 +994,39 @@ key: 产品密钥
- 过去一周:[https://rsshub.app/yande.re/post/popular_recent/1w](https://rsshub.app/yande.re/post/popular_recent/1w)
- 过去一月:[https://rsshub.app/yande.re/post/popular_recent/1m](https://rsshub.app/yande.re/post/popular_recent/1m)
- 过去一年:[https://rsshub.app/yande.re/post/popular_recent/1y](https://rsshub.app/yande.re/post/popular_recent?period=1y)
+
+## GitHub
+
+::: tip 提示
+
+GitHub 官方也提供了一些 RSS:
+
+- 仓库 releases: https://github.com/:owner/:repo/releases.atom
+- 仓库 commits: https://github.com/:owner/:repo/commits.atom
+- 用户动态: https://github.com/:user.atom
+
+:::
+
+### 用户仓库
+
+举例: [https://rsshub.app/github/repos/DIYgod](https://rsshub.app/github/repos/DIYgod)
+
+路由: `/github/repos/:user`
+
+参数: user,用户名
+
+### Trending
+
+举例:
+
+[https://rsshub.app/github/trending/daily](https://rsshub.app/github/trending/daily)
+
+[https://rsshub.app/github/trending/daily/javascript](https://rsshub.app/github/trending/daily/javascript)
+
+路由: `/github/trending/:since/:language?`
+
+参数:
+
+since,时间跨度,可在 [Trending 页](https://github.com/trending/javascript?since=monthly) URL 中找到,可选 daily weekly monthly
+
+language,语言,可在 [Trending 页](https://github.com/trending/javascript?since=monthly) URL 中找到
diff --git a/router.js b/router.js
index 5fb4695765..19dda79459 100644
--- a/router.js
+++ b/router.js
@@ -240,8 +240,9 @@ router.get('/readhub/category/:category', require('./routes/readhub/category'));
if (config.github && config.github.access_token) {
router.get('/github/repos/:user', require('./routes/github/repos'));
} else {
- logger.warn('GitHub RSS is disabled for lacking config.');
+ logger.warn('GitHub Repos RSS is disabled for lacking config.');
}
+router.get('/github/trending/:since/:language?', require('./routes/github/trending'));
// konachan
router.get('/konachan/post', require('./routes/konachan/post'));
diff --git a/routes/github/repos.js b/routes/github/repos.js
index 323174cb0f..8e8f803498 100644
--- a/routes/github/repos.js
+++ b/routes/github/repos.js
@@ -3,34 +3,29 @@ const config = require('../../config');
module.exports = async (ctx) => {
const user = ctx.params.user;
- const uri = `https://api.github.com/users/${user}/repos` + `?access_token=${config.github.access_token}`;
const response = await axios({
method: 'get',
- url: uri,
+ url: `https://api.github.com/users/${user}/repos`,
headers: {
'User-Agent': config.ua,
- Referer: uri,
+ },
+ params: {
+ sort: 'created',
+ access_token: config.github.access_token,
},
});
const data = response.data;
ctx.state.data = {
- title: `GitHub Repos By ${user}`,
- link: uri,
- description: `GitHub Repos By ${user}`,
+ title: `${user}'s GitHub repositories`,
+ link: `https://github.com/${user}`,
item:
data &&
- data.map((item) => {
- let repoDescription = item.description;
- if (repoDescription === null) {
- repoDescription = 'No description added';
- }
- return {
- title: `${item.name}`,
- guid: `${item.id}`,
- description: `${repoDescription}`,
- link: `${item.url}`,
- };
- }),
+ data.map((item) => ({
+ title: item.name,
+ description: item.description || 'No description',
+ pubDate: new Date(item.created_at).toUTCString(),
+ link: item.html_url,
+ })),
};
};
diff --git a/routes/github/trending.js b/routes/github/trending.js
new file mode 100644
index 0000000000..8c87f59bf0
--- /dev/null
+++ b/routes/github/trending.js
@@ -0,0 +1,49 @@
+const axios = require('../../utils/axios');
+const cheerio = require('cheerio');
+const config = require('../../config');
+
+module.exports = async (ctx) => {
+ const since = ctx.params.since;
+ const language = ctx.params.language || '';
+ const url = `https://github.com/trending/${language}?since=${since}`;
+
+ const response = await axios({
+ method: 'get',
+ url: url,
+ headers: {
+ 'User-Agent': config.ua,
+ Referer: url,
+ },
+ });
+
+ const data = response.data;
+
+ const $ = cheerio.load(data);
+ const list = $('.repo-list li');
+
+ ctx.state.data = {
+ title: $('title').text(),
+ link: url,
+ item:
+ list &&
+ list
+ .map((index, item) => {
+ item = $(item);
+ return {
+ title: item.find('h3').text(),
+ description: `${item.find('.py-1').text()}
+
Language: ${item.find('span[itemprop="programmingLanguage"]').text() || 'unknown'}
+
Star: ${item
+ .find('.muted-link')
+ .eq(0)
+ .text()}
+
Fork: ${item
+ .find('.muted-link')
+ .eq(1)
+ .text()}`,
+ link: `https://github.com${item.find('h3 a').attr('href')}`,
+ };
+ })
+ .get(),
+ };
+};