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

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,
};
};