Skip to content

Commit

Permalink
fix(route): rfa missing url property (#9326)
Browse files Browse the repository at this point in the history
* fix(route): rfa missing url property

* docs: add missing en h3 title

* fix: use nullish coalescing operator
  • Loading branch information
TonyRL authored Mar 15, 2022
1 parent 0ec2b01 commit ba198d0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/en/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,8 @@ category 对应的关键词有

## 自由亚洲电台

### 新闻

<Route author="zphw" example="/rfa/mandarin" path="/rfa/:language?/:channel?/:subChannel?" :paramsDesc="['语言,默认 English', '频道', '子频道(如存在)']">

通过指定频道参数,提供比官方源更佳的阅读体验。
Expand Down
3 changes: 0 additions & 3 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
17 changes: 11 additions & 6 deletions lib/routes/rfa/index.js → lib/v2/rfa/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) => {
Expand All @@ -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;
})
)
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/rfa/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:language?/:channel?/:subChannel?': ['zphw'],
};
13 changes: 13 additions & 0 deletions lib/v2/rfa/radar.js
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/v2/rfa/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:language?/:channel?/:subChannel?', require('./index'));
};

0 comments on commit ba198d0

Please sign in to comment.