This commit is contained in:
zph 2021-01-08 17:54:16 +08:00
parent b1ae777b87
commit 30ff4ff172
3 changed files with 76 additions and 0 deletions

View File

@ -247,6 +247,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
### 新聞

View File

@ -3780,4 +3780,7 @@ router.get('/nace/blog/:sort?', require('./routes/nace/blog'));
// Caixin Latest
router.get('/caixin/latest', require('./routes/caixin/latest'));
// Voice of America
router.get('/voa/:language/:channel?', require('./routes/voa/index'));
module.exports = router;

53
lib/routes/voa/index.js Normal file
View File

@ -0,0 +1,53 @@
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;
}
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,
};
};