feat(route): add 希望之声 (#9285)

* feat(route): add 希望之声

* fix(route): change timezone
This commit is contained in:
Fatpandac 2022-03-10 02:26:54 +08:00 committed by GitHub
parent ce511b5b17
commit 073df65935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 1 deletions

View File

@ -1298,6 +1298,16 @@ category 对应的关键词有
<Route author="hoilc" example="/whb/bihui" path="/whb/:category" :paramsDesc="['文汇报分类名,可在该分类的 URL 中找到(即 http://www.whb.cn/zhuzhan/:category/index.html)']" />
## 希望之声
<Route author="Fatpandac" example="/soundofhope/term/203" path="/soundofhope/:channel/:id" :paramsDesc="['频道', '子频道 ID']">
参数均可在官网获取,如:
`https://www.soundofhope.org/term/203` 对应 `/soundofhope/term/203`
</Route>
## 香港 01
### 热门
@ -1598,7 +1608,7 @@ category 对应的关键词有
## 自由亚洲电台
<Route author="zphw" example="/rfa/mandarin" path="/rfa/:language?/:channel?/:subChannel?" :paramsDesc="['语言,默认 English', '频道', '子频道(如存在)']" />
<Route author="zphw" example="/rfa/mandarin" path="/rfa/:language?/:channel?/:subChannel?" :paramsDesc="['语言,默认 English', '频道', '子频道(如存在)']">
通过指定频道参数,提供比官方源更佳的阅读体验。
@ -1607,3 +1617,5 @@ category 对应的关键词有
`https://www.rfa.org/cantonese/news` 对应 `/rfa/cantonese/news`
`https://www.rfa.org/cantonese/news/htm` 对应 `/rfa/cantonese/news/htm`
</Route>

View File

@ -0,0 +1,42 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const host = 'https://www.soundofhope.org';
module.exports = async (ctx) => {
const channel = ctx.params.channel;
const id = ctx.params.id;
const url = `${host}/${channel}/${id}`;
const response = await got(url);
const $ = cheerio.load(response.data);
const title = $('div.left > nav').text().split('/').slice(1).join('');
const list = $('div.item')
.map((_, item) => ({
title: $(item).find('div.title').text(),
link: new URL($(item).find('a').attr('href'), host).href,
}))
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link);
const content = cheerio.load(detailResponse.data);
item.description = content('div.Content__Wrapper-sc-1bvya0-0').html();
item.pubDate = timezone(parseDate(content('div.date').text(), 'YYYY.M.D HH:mm'), -8);
return item;
})
)
);
ctx.state.data = {
title: `希望之声 - ${title}`,
link: url,
item: items,
};
};

View File

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

View File

@ -0,0 +1,13 @@
module.exports = {
'soundofhope.org': {
_name: '希望之声',
'.': [
{
title: '频道',
docs: 'https://docs.rsshub.app/traditional-media.html#xi-wang-zhi-sheng',
source: ['/:channel/:id'],
target: '/soundofhope/:channel/:id',
},
],
},
};

View File

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