feat(route): add FossHub (#10266)

* feat(route): add FossHub

* fix: add pubDate

* fix: parseDate
This commit is contained in:
Ethan Shen 2022-07-21 14:43:53 +08:00 committed by GitHub
parent 8b04fef528
commit 9703916bce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 100 additions and 0 deletions

View File

@ -198,6 +198,12 @@ Language
<RouteEn author="DIYgod" example="/firefox/addons/rsshub-radar" path="/firefox/addons/:id" :paramsDesc="['Add-ons id, can be found in add-ons url']"/>
## FossHub
### Software Update
<RouteEn author="nczitzk" example="/fosshub/qBittorrent" path="/fosshub/:id" :paramsDesc="['Software id, can be found in URL']"/>
## Greasy Fork
### Script Update

View File

@ -240,6 +240,12 @@ pageClass: routes
<Route author="DIYgod" example="/firefox/addons/rsshub-radar" path="/firefox/addons/:id" :paramsDesc="['附加组件 id, 可在应用页 URL 中找到']" />
## FossHub
### Software Update
<Route author="nczitzk" example="/fosshub/qBittorrent" path="/fosshub/:id" :paramsDesc="['软件 id可在对应软件页 URL 中找到']"/>
## Greasy Fork
### 脚本更新

49
lib/v2/fosshub/index.js Normal file
View File

@ -0,0 +1,49 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const id = ctx.params.id ?? '';
const rootUrl = 'https://www.fosshub.com';
const currentUrl = `${rootUrl}/${id}.html`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const version = $('dd[itemprop="softwareVersion"]').first().text();
const items = [
{
title: version,
link: `${currentUrl}#${version}`,
description: art(path.join(__dirname, 'templates/description.art'), {
links: $('.dwn-dl')
.toArray()
.map((l) =>
$(l)
.find('.w')
.toArray()
.map((w) => ({
dt: $(w).find('dt').text(),
dd: $(w).find('dd').html(),
}))
),
changelog: $('div[itemprop="releaseNotes"]').html(),
}),
pubDate: parseDate($('.ma__upd .v').text(), 'MMM DD, YYYY'),
},
];
ctx.state.data = {
title: `${$('#fh-ssd__hl').text()} - FossHub`,
link: currentUrl,
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/:id': ['nczitzk'],
};

13
lib/v2/fosshub/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'fosshub.com': {
_name: 'FossHub',
'.': [
{
title: 'Software Update',
docs: 'https://docs.rsshub.app/program-update.html#fosshub-software-update',
source: ['/'],
target: (params, url) => `/fosshub/${new URL(url).match(/\/(.*?)\.html$/)[1]}`,
},
],
},
};

3
lib/v2/fosshub/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:id', require('./index'));
};

View File

@ -0,0 +1,20 @@
<table>
<tbody>
{{ each links link }}
<tr>
{{ each link l }}
<th>{{ l.dt }}</th>
{{ /each }}
<tr>
<tr>
{{ each link l }}
<td>{{@ l.dd }}</td>
{{ /each }}
<tr>
{{ /each }}
</tbody>
</table>
{{ if changelog }}
<br>
{{@ changelog }}
{{ /if }}