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

This commit is contained in:
Tony
2023-01-27 00:29:02 +08:00
committed by GitHub
parent 11ff4a2f98
commit c08afbfc8d
6 changed files with 89 additions and 39 deletions
+1
View File
@@ -12,4 +12,5 @@ module.exports = {
'/topics/:name/:qs?': ['queensferryme'],
'/trending/:since/:language?/:spoken_language?': ['DIYgod', 'jameschensmith'],
'/user/followers/:user': ['HenryQW'],
'/wiki/:user/:repo/:page?': ['TonyRL'],
};
+39 -33
View File
@@ -2,6 +2,12 @@ module.exports = {
'github.com': {
_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 评论',
docs: 'https://docs.rsshub.app/programming.html#github',
@@ -9,28 +15,16 @@ module.exports = {
target: '/github/comments/:user/:repo/:number',
},
{
title: '用户仓库',
title: '仓库 Contributors',
docs: 'https://docs.rsshub.app/programming.html#github',
source: '/:user',
target: '/github/repos/:user',
source: ['/:user/:repo/graphs/contributors', '/:user/:repo'],
target: '/github/contributors/:user/:repo',
},
{
title: '用户 Followers',
title: '文件 Commits',
docs: 'https://docs.rsshub.app/programming.html#github',
source: '/:user',
target: '/github/user/followers/:user',
},
{
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?',
source: '/:user/:repo/blob/:branch/*filepath',
target: '/github/file/:user/:repo/:branch/:filepath',
},
{
title: '仓库 Issue',
@@ -44,24 +38,18 @@ module.exports = {
source: ['/:user/:repo/pulls', '/:user/:repo/pulls/:id', '/:user/:repo'],
target: '/github/pull/:user/:repo',
},
{
title: '用户仓库',
docs: 'https://docs.rsshub.app/programming.html#github',
source: '/:user',
target: '/github/repos/:user',
},
{
title: '仓库 Stars',
docs: 'https://docs.rsshub.app/programming.html#github',
source: ['/:user/:repo/stargazers', '/: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',
docs: 'https://docs.rsshub.app/programming.html#github',
@@ -69,10 +57,28 @@ module.exports = {
target: '/github/starred_repos/:user',
},
{
title: '仓库 Contributors',
title: 'Topics',
docs: 'https://docs.rsshub.app/programming.html#github',
source: ['/:user/:repo/graphs/contributors', '/:user/:repo'],
target: '/github/contributors/:user/:repo',
source: '/topics',
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',
},
],
},
+1
View File
@@ -13,4 +13,5 @@ module.exports = function (router) {
router.get('/topics/:name/:qs?', require('./topic'));
router.get('/trending/:since/:language/:spoken_language?', require('./trending'));
router.get('/user/followers/:user', require('./follower'));
router.get('/wiki/:user/:repo/:page?', require('./wiki'));
};
+32
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,
};
};