feat(route): add Tribal Football (#10238)

* feat(route): add Tribal Football

Signed-off-by: Rongrong <i@rong.moe>

* fix: insecure HTTP
This commit is contained in:
Rongrong 2022-07-17 21:18:47 +08:00 committed by GitHub
parent ee475dd3a1
commit f0c5610ba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 105 additions and 0 deletions

View File

@ -739,6 +739,12 @@ Provides all of the Thrillist articles with the specified tag.
</RouteEn>
## Tribal Football
### Latest News
<RouteEn author="Rongronggg9" example="/tribalfootball" path="/tribalfootball" />
## VOA News
### Day in Photos

View File

@ -1317,6 +1317,12 @@ Provides all of the Thrillist articles with the specified tag.
</Route>
## Tribal Football
### Latest News
<Route author="Rongronggg9" example="/tribalfootball" path="/tribalfootball" />
## Uwants
### 版塊

View File

@ -0,0 +1,68 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const rssUrl = 'https://www.tribalfootball.com/rss/mediafed/general/rss.xml';
module.exports = async (ctx) => {
const rss = await got(rssUrl);
const $ = cheerio.load(rss.data, { xmlMode: true });
const items = $('rss > channel > item')
.map((_, item) => {
const $item = $(item);
let link = $item.find('link').text();
link = new URL(link);
link.search = '';
link = link.href;
return {
title: $item.find('title').text(),
description: $item.find('description').text(),
link,
guid: $item.find('guid').text(),
pubDate: parseDate($item.find('pubDate').text()),
author: $item.find('dc\\:creator').text(),
_header_image: $item.find('enclosure').attr('url'),
};
})
.get();
await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const response = await got(item.link);
const $ = cheerio.load(response.data);
const title = $('head > title').text().replace(' - Tribal Football', '');
let desc = $('.articleBody');
desc.find('.ad').remove();
// <p><br><i>AD</i><span></span></p>
const ad = desc.find('p > br:first-child').next('i');
const adNextSpan = ad.next('span');
if (adNextSpan.length && !adNextSpan.text() && !adNextSpan.next().length) {
ad.parent().remove();
}
desc = desc.html();
desc = art(path.join(__dirname, 'templates/plus_header.art'), {
desc,
header_image: item._header_image,
});
item.title = title || item.title;
item.description = desc || item.description;
delete item._header_image;
return item;
})
)
);
ctx.state.data = {
title: 'Tribal Football - Latest',
description: 'Tribal Football - Football News, Soccer News, Transfers & Rumours',
link: 'https://www.tribalfootball.com/articles',
image: 'https://www.tribalfootball.com/images/tribal-logo-rss.png',
item: items,
};
};

View File

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

View File

@ -0,0 +1,13 @@
module.exports = {
'tribalfootball.com': {
_name: 'Tribal Football',
'.': [
{
title: 'Latest News',
docs: 'https://docs.rsshub.app/new-media.html#tribal-football',
source: ['/'],
target: '/tribalfootball',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/', require('./latest'));
};

View File

@ -0,0 +1,6 @@
{{ if header_image }}
<p>
<img src="{{ header_image }}">
</p>
{{ /if }}
{{@ desc }}