From 0889aeeff765e163d2622ca1b0cd677232029d02 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 17 Jul 2021 17:38:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E9=9D=A0=E8=B0=B1=E6=96=B0?= =?UTF-8?q?=E9=97=BB=20(#7879)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/traditional-media.md | 2 +- lib/router.js | 2 +- lib/routes/kaopunews/all.js | 30 ------------------------------ lib/routes/kaopunews/index.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 32 deletions(-) delete mode 100644 lib/routes/kaopunews/all.js create mode 100644 lib/routes/kaopunews/index.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index b9480c4d5..981664ada 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -740,7 +740,7 @@ category 对应的关键词有 ### 新闻聚合 - + ## 连线 Wired diff --git a/lib/router.js b/lib/router.js index 79f831566..fcc8d60b6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/kaopunews/all.js b/lib/routes/kaopunews/all.js deleted file mode 100644 index 8085a9f93..000000000 --- a/lib/routes/kaopunews/all.js +++ /dev/null @@ -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(), - }; -}; diff --git a/lib/routes/kaopunews/index.js b/lib/routes/kaopunews/index.js new file mode 100644 index 000000000..e848e9c55 --- /dev/null +++ b/lib/routes/kaopunews/index.js @@ -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: `

${item.story_summary}

`, + })); + + ctx.state.data = { + title: language === 'zh-hant' ? '靠譜新聞' : '靠谱新闻', + link: currentUrl, + item: items, + }; +};