feat(route): github wiki history (#11700)

This commit is contained in:
Tony
2023-01-27 03:29:02 +11:00
committed by GitHub
parent 11ff4a2f98
commit c08afbfc8d
6 changed files with 89 additions and 39 deletions

View File

@@ -122,10 +122,11 @@ Category
GitHub provides some official RSS feeds: GitHub provides some official RSS feeds:
- Repo releases: https://github.com/:owner/:repo/releases.atom - Repo releases: `https://github.com/:owner/:repo/releases.atom`
- Repo commits: https://github.com/:owner/:repo/commits.atom - Repo commits: `https://github.com/:owner/:repo/commits.atom`
- User activities: https://github.com/:user.atom - User activities: `https://github.com/:user.atom`
- Private feed: https://github.com/:user.private.atom?token=:secret (You can find **Subscribe to your news feed** in [dashboard](https://github.com) page after login) - Private feed: `https://github.com/:user.private.atom?token=:secret` (You can find **Subscribe to your news feed** in [dashboard](https://github.com) page after login)
- Wiki history: `https://github.com/:owner/:repo/wiki.atom`
::: :::
@@ -211,7 +212,11 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen
### Issue / Pull Request comments ### Issue / Pull Request comments
<RouteEn author="TonyRL" example="/github/comments/DIYgod/RSSHub/8116" path="/github/comments/:user/:repo/:number" :paramsDesc="['User / Org name', 'Repo name', 'Issue or pull number']"/> <RouteEn author="TonyRL" example="/github/comments/DIYgod/RSSHub/8116" path="/github/comments/:user/:repo/:number" :paramsDesc="['User / Org name', 'Repo name', 'Issue or pull number']" radar="1" rssbud="1"/>
### Wiki History
<RouteEn author="TonyRL" example="/github/wiki/flutter/flutter/Roadmap" path="/github/wiki/:user/:repo/:page?" :paramsDesc="['User / Org name', 'Repo name', 'Page slug, can be found in URL, empty means Home']" radar="1" rssbud="1"/>
## GitLab ## GitLab

View File

@@ -222,6 +222,7 @@ GitHub 官方也提供了一些 RSS:
- 仓库 commits: `https://github.com/:owner/:repo/commits.atom` - 仓库 commits: `https://github.com/:owner/:repo/commits.atom`
- 用户动态: `https://github.com/:user.atom` - 用户动态: `https://github.com/:user.atom`
- 专属动态: `https://github.com/:user.private.atom?token=:secret` (登录后在[仪表盘页面](https://github.com)找到 **Subscribe to your news feed** 字样即可) - 专属动态: `https://github.com/:user.private.atom?token=:secret` (登录后在[仪表盘页面](https://github.com)找到 **Subscribe to your news feed** 字样即可)
- Wiki 历史: `https://github.com/:owner/:repo/wiki.atom`
::: :::
@@ -307,7 +308,11 @@ GitHub 官方也提供了一些 RSS:
### Issue / Pull Request 评论 ### Issue / Pull Request 评论
<Route author="TonyRL" example="/github/comments/DIYgod/RSSHub/8116" path="/github/comments/:user/:repo/:number" :paramsDesc="['用户名', '仓库', 'Issue 或 pull 编号']"/> <Route author="TonyRL" example="/github/comments/DIYgod/RSSHub/8116" path="/github/comments/:user/:repo/:number" :paramsDesc="['用户名', '仓库', 'Issue 或 pull 编号']" radar="1" rssbud="1"/>
### Wiki 历史
<Route author="TonyRL" example="/github/wiki/flutter/flutter/Roadmap" path="/github/wiki/:user/:repo/:page?" :paramsDesc="['用户名', '仓库名', '页面 Slug可在 URL 中找到,留空表示主页']" radar="1" rssbud="1"/>
## GitLab ## GitLab

View File

@@ -12,4 +12,5 @@ module.exports = {
'/topics/:name/:qs?': ['queensferryme'], '/topics/:name/:qs?': ['queensferryme'],
'/trending/:since/:language?/:spoken_language?': ['DIYgod', 'jameschensmith'], '/trending/:since/:language?/:spoken_language?': ['DIYgod', 'jameschensmith'],
'/user/followers/:user': ['HenryQW'], '/user/followers/:user': ['HenryQW'],
'/wiki/:user/:repo/:page?': ['TonyRL'],
}; };

View File

@@ -2,6 +2,12 @@ module.exports = {
'github.com': { 'github.com': {
_name: 'GitHub', _name: 'GitHub',
'.': [ '.': [
{
title: '仓库 Branches',
docs: 'https://docs.rsshub.app/programming.html#github',
source: ['/:user/:repo/branches', '/:user/:repo'],
target: '/github/branches/:user/:repo',
},
{ {
title: 'Issues / Pull Requests 评论', title: 'Issues / Pull Requests 评论',
docs: 'https://docs.rsshub.app/programming.html#github', docs: 'https://docs.rsshub.app/programming.html#github',
@@ -9,28 +15,16 @@ module.exports = {
target: '/github/comments/:user/:repo/:number', target: '/github/comments/:user/:repo/:number',
}, },
{ {
title: '用户仓库', title: '仓库 Contributors',
docs: 'https://docs.rsshub.app/programming.html#github', docs: 'https://docs.rsshub.app/programming.html#github',
source: '/:user', source: ['/:user/:repo/graphs/contributors', '/:user/:repo'],
target: '/github/repos/:user', target: '/github/contributors/:user/:repo',
}, },
{ {
title: '用户 Followers', title: '文件 Commits',
docs: 'https://docs.rsshub.app/programming.html#github', docs: 'https://docs.rsshub.app/programming.html#github',
source: '/:user', source: '/:user/:repo/blob/:branch/*filepath',
target: '/github/user/followers/:user', target: '/github/file/:user/:repo/:branch/:filepath',
},
{
title: 'Trending',
docs: 'https://docs.rsshub.app/programming.html#github',
source: '/trending',
target: '/github/trending/:since',
},
{
title: 'Trending',
docs: 'https://docs.rsshub.app/programming.html#github',
source: '/topics',
target: '/github/topics/:name/:qs?',
}, },
{ {
title: '仓库 Issue', title: '仓库 Issue',
@@ -44,24 +38,18 @@ module.exports = {
source: ['/:user/:repo/pulls', '/:user/:repo/pulls/:id', '/:user/:repo'], source: ['/:user/:repo/pulls', '/:user/:repo/pulls/:id', '/:user/:repo'],
target: '/github/pull/:user/:repo', target: '/github/pull/:user/:repo',
}, },
{
title: '用户仓库',
docs: 'https://docs.rsshub.app/programming.html#github',
source: '/:user',
target: '/github/repos/:user',
},
{ {
title: '仓库 Stars', title: '仓库 Stars',
docs: 'https://docs.rsshub.app/programming.html#github', docs: 'https://docs.rsshub.app/programming.html#github',
source: ['/:user/:repo/stargazers', '/:user/:repo'], source: ['/:user/:repo/stargazers', '/:user/:repo'],
target: '/github/stars/:user/:repo', target: '/github/stars/:user/:repo',
}, },
{
title: '仓库 Branches',
docs: 'https://docs.rsshub.app/programming.html#github',
source: ['/:user/:repo/branches', '/:user/:repo'],
target: '/github/branches/:user/:repo',
},
{
title: '文件 Commits',
docs: 'https://docs.rsshub.app/programming.html#github',
source: '/:user/:repo/blob/:branch/*filepath',
target: '/github/file/:user/:repo/:branch/:filepath',
},
{ {
title: '用户 Starred Repositories', title: '用户 Starred Repositories',
docs: 'https://docs.rsshub.app/programming.html#github', docs: 'https://docs.rsshub.app/programming.html#github',
@@ -69,10 +57,28 @@ module.exports = {
target: '/github/starred_repos/:user', target: '/github/starred_repos/:user',
}, },
{ {
title: '仓库 Contributors', title: 'Topics',
docs: 'https://docs.rsshub.app/programming.html#github', docs: 'https://docs.rsshub.app/programming.html#github',
source: ['/:user/:repo/graphs/contributors', '/:user/:repo'], source: '/topics',
target: '/github/contributors/:user/:repo', target: '/github/topics/:name/:qs?',
},
{
title: 'Trending',
docs: 'https://docs.rsshub.app/programming.html#github',
source: '/trending',
target: '/github/trending/:since',
},
{
title: '用户 Followers',
docs: 'https://docs.rsshub.app/programming.html#github',
source: '/:user',
target: '/github/user/followers/:user',
},
{
title: 'Wiki 历史',
docs: 'https://docs.rsshub.app/programming.html#github',
source: ['/:user/:repo/wiki/:page/_history', '/:user/:repo/wiki/:page', '/:user/:repo/wiki/_history', '/:user/:repo/wiki'],
target: '/github/wiki/:user/:repo/:page',
}, },
], ],
}, },

View File

@@ -13,4 +13,5 @@ module.exports = function (router) {
router.get('/topics/:name/:qs?', require('./topic')); router.get('/topics/:name/:qs?', require('./topic'));
router.get('/trending/:since/:language/:spoken_language?', require('./trending')); router.get('/trending/:since/:language/:spoken_language?', require('./trending'));
router.get('/user/followers/:user', require('./follower')); router.get('/user/followers/:user', require('./follower'));
router.get('/wiki/:user/:repo/:page?', require('./wiki'));
}; };

32
lib/v2/github/wiki.js Normal file
View File

@@ -0,0 +1,32 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const baseUrl = 'https://github.com';
module.exports = async (ctx) => {
const { user, repo, page } = ctx.params;
const url = `${baseUrl}/${user}/${repo}/wiki${page ? `/${page}` : ''}/_history`;
const { data } = await got(url);
const $ = cheerio.load(data);
const items = $('.js-wiki-history-revision')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('.h5').text(),
author: item.find('.mt-1 a').text(),
pubDate: parseDate(item.find('relative-time').attr('datetime')),
link: `${baseUrl}${item.find('.text-mono a').attr('href')}`,
};
});
ctx.state.data = {
title: `${$('.gh-header-title').text()} - ${user}/${repo}`,
link: url,
item: items,
};
};