feat(route): add greasyfork script version history and script feedback (#10662)
* feat(route): add greasyfork script version history * feat(route): add greasyfork script feedback * refactor(route): remove unnecessary `lang` param * fix(route): ensure the changelog is extracted correctly
This commit is contained in:
@@ -238,6 +238,14 @@ Language
|
||||
|
||||
<RouteEn author="imlonghao" path="/greasyfork/:language/:domain?" example="/greasyfork/en/google.com" :paramsDesc="['language, located on the top right corner of Greasy Fork\'s search page, set to `all` for including all languages', 'the script\'s target domain']" radar="1" />
|
||||
|
||||
### Script Version History
|
||||
|
||||
<RouteEn author="miles170" example="/greasyfork/scripts/431691-bypass-all-shortlinks/versions" path="/greasyfork/scripts/:script/versions" :paramsDesc="['Script id, can be found in URL']" radar="1" />
|
||||
|
||||
### Script Feedback
|
||||
|
||||
<RouteEn author="miles170" example="/greasyfork/scripts/431691-bypass-all-shortlinks/feedback" path="/greasyfork/scripts/:script/feedback" :paramsDesc="['Script id, can be found in URL']" radar="1" />
|
||||
|
||||
## Hugo
|
||||
|
||||
### Release News
|
||||
|
||||
@@ -270,6 +270,14 @@ pageClass: routes
|
||||
|
||||
<Route author="imlonghao" example="/greasyfork/zh-CN/bilibili.com" path="/greasyfork/:language/:domain?" :paramsDesc="['语言, 可在网站右上角找到, `all` 为所有语言', '按脚本生效域名过滤, 可选']" radar="1"/>
|
||||
|
||||
### 脚本版本历史
|
||||
|
||||
<Route author="miles170" example="/greasyfork/scripts/14178-ac-baidu-重定向优化百度搜狗谷歌必应搜索-favicon-双列/versions" path="/greasyfork/scripts/:script/versions" :paramsDesc="['脚本 id,可在对应脚本页 URL 中找到']" radar="1" />
|
||||
|
||||
### 脚本反馈
|
||||
|
||||
<Route author="miles170" example="/greasyfork/scripts/14178-ac-baidu-重定向优化百度搜狗谷歌必应搜索-favicon-双列/feedback" path="/greasyfork/scripts/:script/feedback" :paramsDesc="['脚本 id,可在对应脚本页 URL 中找到']" radar="1" />
|
||||
|
||||
## Hugo
|
||||
|
||||
### 更新日志
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const script = ctx.params.script;
|
||||
const rootUrl = 'https://greasyfork.org';
|
||||
const currentUrl = `${rootUrl}/scripts/${script}/feedback`;
|
||||
const response = await got(currentUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
description: $('meta[name=description]').attr('content'),
|
||||
item: $('.script-discussion-list .discussion-list-container .discussion-list-item')
|
||||
.get()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
const metaItem = item.find('.discussion-meta .discussion-meta-item').eq(0);
|
||||
const discussionTitle = item.find('.discussion-title');
|
||||
|
||||
return {
|
||||
title: discussionTitle.text().trim(),
|
||||
author: metaItem.find('a').text(),
|
||||
pubDate: parseDate(metaItem.find('gf-relative-time').attr('datetime')),
|
||||
link: rootUrl + discussionTitle.attr('href'),
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
@@ -1,3 +1,5 @@
|
||||
module.exports = {
|
||||
'/:language/:domain?': ['imlonghao', 'miles170'],
|
||||
'/scripts/:script/feedback': ['miles170'],
|
||||
'/scripts/:script/versions': ['miles170'],
|
||||
};
|
||||
|
||||
@@ -8,6 +8,18 @@ module.exports = {
|
||||
source: ['/:language', '/:language/scripts/by-site/:domain?'],
|
||||
target: '/greasyfork/:language/:domain?',
|
||||
},
|
||||
{
|
||||
title: 'Feedback',
|
||||
docs: 'https://docs.rsshub.app/program-update.html#greasy-fork',
|
||||
source: '/:language/scripts/:script/feedback',
|
||||
target: '/greasyfork/scripts/:script/feedback',
|
||||
},
|
||||
{
|
||||
title: 'Version history',
|
||||
docs: 'https://docs.rsshub.app/program-update.html#greasy-fork',
|
||||
source: '/:language/scripts/:script/versions',
|
||||
target: '/greasyfork/scripts/:script/versions',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/:language/:domain?', require('./scripts'));
|
||||
router.get('/scripts/:script/feedback', require('./feedback'));
|
||||
router.get('/scripts/:script/versions', require('./versions'));
|
||||
};
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const script = ctx.params.script;
|
||||
const currentUrl = `https://greasyfork.org/scripts/${script}/versions`;
|
||||
const response = await got(currentUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
description: $('meta[name=description]').attr('content'),
|
||||
item: $('.history_versions li')
|
||||
.get()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
const versionNumberLink = item.find('.version-number a');
|
||||
|
||||
return {
|
||||
title: versionNumberLink.text(),
|
||||
description: item.find('.version-changelog').text().trim(),
|
||||
pubDate: parseDate(item.find('gf-relative-time').attr('datetime')),
|
||||
link: versionNumberLink.attr('href'),
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user