From 970db993ee062de9875d024961ffbdf88de3ac70 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 15:32:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20Now=20=E7=86=B1=E9=96=80?= =?UTF-8?q?=E6=96=B0=E8=81=9E=20(#8093)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: DIYgod --- docs/traditional-media.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/now/rank.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 lib/routes/now/rank.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 31a6712b1..68666ab5c 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -213,6 +213,12 @@ pageClass: routes +## Now 新聞 + +### 熱門 + + + ## Phoronix ### 新闻与评测 diff --git a/lib/router.js b/lib/router.js index 9de5aadae..b70be1d84 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4207,6 +4207,9 @@ router.get('/right/forum/:id?', lazyloadRouteHandler('./routes/right/forum')); // 香港經濟日報 router.get('/hket/:category?', lazyloadRouteHandler('./routes/hket/index')); +// Now新聞 +router.get('/now/news/rank', lazyloadRouteHandler('./routes/now/rank')); + // s-hentai router.get('/s-hentai/:id?', lazyloadRouteHandler('./routes/s-hentai')); diff --git a/lib/routes/now/rank.js b/lib/routes/now/rank.js new file mode 100644 index 000000000..f65abc831 --- /dev/null +++ b/lib/routes/now/rank.js @@ -0,0 +1,31 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +const sources = { + nownews: '/home/local/player?newsId=', + nowsports: '/home/news/details?id=', + nowfinace: '/news/post.php?id=', +}; + +module.exports = async (ctx) => { + const rootUrl = (source) => `https://${source}.now.com`; + const currentUrl = `${rootUrl('news')}/api/getRankNewsList?pageSize=221`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const items = response.data.map((item) => ({ + title: item.title, + pubDate: parseDate(item.publishDate), + description: `${item.summary || ''}`, + link: `${rootUrl(item.newsSource.replace('now', ''))}${sources[item.newsSource]}${item.newsId}`, + })); + + ctx.state.data = { + title: '熱門 | Now 新聞', + link: rootUrl('news'), + item: items, + }; +};