fix(route): rfa missing url property (#9326)

* fix(route): rfa missing url property

* docs: add missing en h3 title

* fix: use nullish coalescing operator
This commit is contained in:
Tony 2022-03-16 04:14:49 +07:00 committed by GitHub
parent 0ec2b01ec2
commit ba198d09c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 9 deletions

View File

@ -221,6 +221,8 @@ Only `s00017` is in English.
## Radio Free Asia (RFA)
### News
<RouteEn author="zphw" example="/rfa/english" path="/rfa/:language?/:channel?/:subChannel?" :paramsDesc="['language, English by default', 'channel', 'subchannel, where applicable']" />
Delivers a better experience by supporting parameter specification.

View File

@ -1663,6 +1663,8 @@ category 对应的关键词有
## 自由亚洲电台
### 新闻
<Route author="zphw" example="/rfa/mandarin" path="/rfa/:language?/:channel?/:subChannel?" :paramsDesc="['语言,默认 English', '频道', '子频道(如存在)']">
通过指定频道参数,提供比官方源更佳的阅读体验。

View File

@ -3732,9 +3732,6 @@ router.get('/simpread/notice', lazyloadRouteHandler('./routes/simpread/notice'))
// SimpRead-更新日志
router.get('/simpread/changelog', lazyloadRouteHandler('./routes/simpread/changelog'));
// Radio Free Asia
router.get('/rfa/:language?/:channel?/:subChannel?', lazyloadRouteHandler('./routes/rfa/index'));
// booth.pm
router.get('/booth.pm/shop/:subdomain', lazyloadRouteHandler('./routes/booth-pm/shop'));

View File

@ -1,8 +1,9 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
let url = 'https://www.rfa.org/' + (ctx.params.language || 'english');
let url = 'https://www.rfa.org/' + (ctx.params.language ?? 'english');
if (ctx.params.channel) {
url += '/' + ctx.params.channel;
@ -11,10 +12,10 @@ module.exports = async (ctx) => {
url += '/' + ctx.params.subChannel;
}
const response = await got.get(url);
const response = await got(url);
const $ = cheerio.load(response.data);
const selectors = ['div[id=topstorywidefulltease]', 'div.two_featured', 'div.three_featured', 'div.single_column_teaser', 'div.sectionteaser', 'div.specialwrap'];
const selectors = ['div[id=topstorywidefull]', 'div.two_featured', 'div.three_featured', 'div.single_column_teaser', 'div.sectionteaser', 'div.specialwrap'];
const list = [];
selectors.forEach((selector) => {
$(selector).each((_, e) => {
@ -28,11 +29,15 @@ module.exports = async (ctx) => {
const result = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const content = await got.get(item.link);
const content = await got(item.link);
const description = cheerio.load(content.data);
item.description = description('div[id=storytext]').html();
item.pubDate = new Date(description('span[id=story_date]').text()).toUTCString();
item.description = description('#headerimg').html() + description('div[id=storytext]').html();
item.pubDate = parseDate(description('span[id=story_date]').text());
if (description('meta[property=og:audio]').attr('content') !== undefined) {
item.enclosure_url = description('meta[property=og:audio]').attr('content');
item.enclosure_type = description('meta[property=og:audio:type]').attr('content');
}
return item;
})
)

3
lib/v2/rfa/maintainer.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
'/:language?/:channel?/:subChannel?': ['zphw'],
};

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

@ -0,0 +1,13 @@
module.exports = {
'rfa.org': {
_name: '自由亚洲电台',
'.': [
{
title: '新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#zi-you-ya-zhou-dian-tai',
source: '/:language/:channel/:subChannel',
target: '/rfa/:language/:channel/:subChannel',
},
],
},
};

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

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:language?/:channel?/:subChannel?', require('./index'));
};