From ae83239411df367132176d715a21936ba0d0c4e7 Mon Sep 17 00:00:00 2001 From: ingjieye Date: Wed, 29 Nov 2023 14:55:57 +0800 Subject: [PATCH] feat(route): Add script sorting for greasyfork --- lib/v2/greasyfork/maintainer.js | 1 + lib/v2/greasyfork/router.js | 1 + lib/v2/greasyfork/scripts.js | 9 +++++---- website/docs/routes/program-update.mdx | 13 +++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/v2/greasyfork/maintainer.js b/lib/v2/greasyfork/maintainer.js index d17e37b05c1008..43ca727f882ae3 100644 --- a/lib/v2/greasyfork/maintainer.js +++ b/lib/v2/greasyfork/maintainer.js @@ -2,4 +2,5 @@ module.exports = { '/:language/:domain?': ['imlonghao', 'miles170'], '/scripts/:script/feedback': ['miles170'], '/scripts/:script/versions': ['miles170'], + '/scripts/sort/:sort/:language?': ['ingjieye'], }; diff --git a/lib/v2/greasyfork/router.js b/lib/v2/greasyfork/router.js index 0443d66a49f3b1..3ba05300e37c3b 100644 --- a/lib/v2/greasyfork/router.js +++ b/lib/v2/greasyfork/router.js @@ -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')); }; diff --git a/lib/v2/greasyfork/scripts.js b/lib/v2/greasyfork/scripts.js index b3d0659265ddfb..6885ce0d20f2df 100644 --- a/lib/v2/greasyfork/scripts.js +++ b/lib/v2/greasyfork/scripts.js @@ -3,17 +3,18 @@ const cheerio = require('cheerio'); const queryString = require('query-string'); 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({ filter_locale, - sort: 'updated', + sort, }), }); const $ = cheerio.load(res.data); diff --git a/website/docs/routes/program-update.mdx b/website/docs/routes/program-update.mdx index 34fe348423db5e..05e138712b33ea 100644 --- a/website/docs/routes/program-update.mdx +++ b/website/docs/routes/program-update.mdx @@ -351,6 +351,19 @@ Language +### Script Ranking {#greasy-fork-script-ranking} + + + +| 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}