fix(route): 靠谱新闻 (#7879)

This commit is contained in:
Ethan Shen 2021-07-17 17:38:49 +08:00 committed by GitHub
parent e949195db1
commit 0889aeeff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 32 deletions

View File

@ -740,7 +740,7 @@ category 对应的关键词有
### 新闻聚合
<Route author="wushijishan" example="/kaopunews/all" path="/kaopunews/all"/>
<Route author="wushijishan nczitzk" example="/kaopunews/:language?" path="/kaopunews" :paramsDesc="['语言,可选 zh-hans 即简体中文,或 zh-hant 即繁体中文']"/>
## 连线 Wired

View File

@ -3157,7 +3157,7 @@ router.get('/erbingapp/news', require('./routes/erbingapp/news'));
router.get('/dsb/area/:area', require('./routes/dsb/area'));
// 靠谱新闻
router.get('/kaopunews/all', require('./routes/kaopunews/all'));
router.get('/kaopunews/:language?', require('./routes/kaopunews'));
// Reuters
router.get('/reuters/theWire', require('./routes/reuters/theWire'));

View File

@ -1,30 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: 'https://kaopu.news/',
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('a[target="_blank"]');
ctx.state.data = {
title: '靠谱新闻',
link: 'https://kaopu.news/',
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: `${item.find('h3').text()}(${item.attr('class').substring(8)})`,
description: item.find('h3').next().next().text(),
link: item.attr('href'),
};
})
.get(),
};
};

View File

@ -0,0 +1,28 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const language = ctx.params.language || '';
const rootUrl = 'https://kaopu.news';
const currentUrl = `${rootUrl}/${language === 'zh-hant' ? 'zh-hant' : 'index'}.html`;
const apiUrl = `https://kaopucdn.azureedge.net/jsondata/news_han${language === 'zh-hant' ? 't' : 's'}_0.json`;
const response = await got({
method: 'get',
url: apiUrl,
});
const items = response.data.map((item) => ({
link: item.link,
title: item.title,
author: item.publisher,
pubDate: new Date(item.first_seen * 1000),
description: `<p>${item.story_summary}</p>`,
}));
ctx.state.data = {
title: language === 'zh-hant' ? '靠譜新聞' : '靠谱新闻',
link: currentUrl,
item: items,
};
};