Merge pull request #6634 from zphw/feature/voa

feat: add Voice of America
This commit is contained in:
NeverBehave
2021-01-10 21:21:38 -05:00
committed by GitHub
3 changed files with 77 additions and 0 deletions
+20
View File
@@ -268,6 +268,26 @@ Solidot 提供的 feed:
<Route author="emdoe" example="/udn/global/鏡頭背後" path="/udn/global/:tid" :paramsDesc="['標籤名稱,請在轉角國際首頁獲取;如果選擇輸入 `newest` 則輸出最新文章']">
## Voice of America (VOA)
透過提取全文,以獲得更好的閱讀體驗
<Route author="zphw" example="/voa/cantonese/zprtie-ttp" path="/voa/:language/:channel?" :paramsDesc="['語言','頻道,可於官網獲取']">
`语言`
| 粵語 | 中文 | 藏語 |
| --------- | ------- | ------- |
| cantonese | chinese | tibetan |
`频道`
可於各語言官網聚合新聞處 (如 <https://www.voacantonese.com/rssfeeds>) 獲取
例如 `https://www.voacantonese.com/api/zyrtyequty` 將對應 `/voa/cantonese/zyrtyequty`
</Route>
## Yahoo
### 新聞
+2
View File
@@ -3795,6 +3795,8 @@ router.get('/semiconductors/latest-news', require('./routes/semiconductors/lates
// VOA News
router.get('/voa/day-photos', require('./routes/voa/day-photos'));
// Voice of America
router.get('/voa/:language/:channel?', require('./routes/voa/index'));
// 留园网
router.get('/6park/:id?/:type?/:keyword?', require('./routes/6park/index'));
+55
View File
@@ -0,0 +1,55 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
let baseURL;
switch (ctx.params.language) {
case 'cantonese':
baseURL = 'https://www.voacantonese.com/';
break;
case 'chinese':
baseURL = 'https://www.voachinese.com/';
break;
case 'tibetan':
baseURL = 'https://www.voatibetan.com/';
break;
default:
throw Error('The language specified does not exist');
}
const response = await got.get(baseURL + 'api/' + (ctx.params.channel || ''));
const $ = cheerio.load(response.data);
const list = [];
$('item').each(function (_, e) {
const item = {};
item.title = $(e).find('title').first().text();
item.link = $(e).find('guid').first().text();
item.pubDate = $(e).find('pubDate').first().text();
item.description = $(e).find('description').first().text();
list.push(item);
});
const result = await Promise.all(
list
.filter((item) => item.link)
.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const content = await got.get(item.link);
const description = cheerio.load(content.data);
description('.wsw__embed').remove();
item.description = description('div#article-content div').first().html() ? description('div.cover-media') + description('div#article-content div').first().html() : item.description;
return item;
})
)
);
ctx.state.data = {
title: $('channel title').first().text(),
link: baseURL,
item: result,
};
};