feat(route): Add script sorting for greasyfork (#13908)
* feat(route): Add script sorting for greasyfork * feat: add pubDate and author ---------
This commit is contained in:
parent
8b04f42705
commit
d03b2c41bc
|
|
@ -2,4 +2,5 @@ module.exports = {
|
|||
'/:language/:domain?': ['imlonghao', 'miles170'],
|
||||
'/scripts/:script/feedback': ['miles170'],
|
||||
'/scripts/:script/versions': ['miles170'],
|
||||
'/scripts/sort/:sort/:language?': ['ingjieye'],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@ module.exports = (router) => {
|
|||
router.get('/:language/:domain?', require('./scripts'));
|
||||
router.get('/scripts/:script/feedback', require('./feedback'));
|
||||
router.get('/scripts/:script/versions', require('./versions'));
|
||||
router.get('/scripts/sort/:sort/:language?', require('./scripts'));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,39 +1,44 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const queryString = require('query-string');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const language = ctx.params.language === 'all' ? 'zh-CN' : ctx.params.language;
|
||||
const language = ctx.params.language === 'all' ? 'zh-CN' : ctx.params.language || 'zh-CN';
|
||||
const domain = ctx.params.domain;
|
||||
const filter_locale = ctx.params.language === 'all' ? 0 : 1;
|
||||
const url = domain ? `by-site/${domain}` : '';
|
||||
const currentUrl = `https://greasyfork.org/${language}/scripts/${url}`;
|
||||
const sort = ctx.params.sort ? ctx.params.sort : 'updated';
|
||||
const url = domain ? `/by-site/${domain}` : '';
|
||||
const currentUrl = `https://greasyfork.org/${language}/scripts${url}`;
|
||||
const res = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
searchParams: queryString.stringify({
|
||||
searchParams: {
|
||||
filter_locale,
|
||||
sort: 'updated',
|
||||
}),
|
||||
sort,
|
||||
},
|
||||
});
|
||||
const $ = cheerio.load(res.data);
|
||||
const list = $('.script-list').find('h2');
|
||||
const list = $('.script-list').find('article');
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').first().text(),
|
||||
link: currentUrl,
|
||||
description: $('meta[name=description]').attr('content'),
|
||||
item:
|
||||
list &&
|
||||
list
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('a').text(),
|
||||
description: item.find('.description').text(),
|
||||
link: item.find('a').attr('href'),
|
||||
};
|
||||
})
|
||||
.get(),
|
||||
item: list?.toArray().map((item) => {
|
||||
item = $(item);
|
||||
const h2 = item.find('h2');
|
||||
return {
|
||||
title: h2.find('a').text(),
|
||||
description: h2.find('.description').text(),
|
||||
link: new URL(h2.find('a').attr('href'), 'https://greasyfork.org').href,
|
||||
pubDate: parseDate(item.find('.script-list-created-date relative-time').attr('datetime')),
|
||||
updated: parseDate(item.find('.script-list-updated-date relative-time').attr('datetime')),
|
||||
author: item
|
||||
.find('.script-list-author a')
|
||||
.toArray()
|
||||
.map((a) => $(a).text())
|
||||
.join(', '),
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -351,6 +351,19 @@ Language
|
|||
|
||||
<Route 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" />
|
||||
|
||||
### Script Ranking {#greasy-fork-script-ranking}
|
||||
|
||||
<Route author="ingjieye" example="/greasyfork/scripts/sort/today/all" path="/greasyfork/scripts/sort/:sort/:language?" paramsDesc={['Sort method, see below table', 'Language, located on the top right corner of Greasy Fork\'s search page, set to all for including all languages']} />
|
||||
|
||||
| Sort | Description |
|
||||
| -------------- | ---------------- |
|
||||
| today | Daily installs |
|
||||
| total_installs | Total installs |
|
||||
| ratings | Ratings |
|
||||
| created | Created date |
|
||||
| updated | Updated date |
|
||||
| name | Name |
|
||||
|
||||
## Hugo {#hugo}
|
||||
|
||||
### Release News {#hugo-release-news}
|
||||
|
|
|
|||
Loading…
Reference in New Issue