feat(route): add Now 熱門新聞 (#8093)

Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
Ethan Shen 2021-11-27 15:32:37 +08:00 committed by GitHub
parent e9eebb1998
commit 970db993ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 0 deletions

View File

@ -213,6 +213,12 @@ pageClass: routes
<Route author="Andiedie" example="/nhk/news_web_easy" path="/nhk/news_web_easy"/>
## Now 新聞
### 熱門
<Route author="nczitzk" example="/now/news/rank" path="/now/news/rank"/>
## Phoronix
### 新闻与评测

View File

@ -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'));

31
lib/routes/now/rank.js Normal file
View File

@ -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: `<img src="${item.imageUrl}">${item.summary || ''}`,
link: `${rootUrl(item.newsSource.replace('now', ''))}${sources[item.newsSource]}${item.newsId}`,
}));
ctx.state.data = {
title: '熱門 | Now 新聞',
link: rootUrl('news'),
item: items,
};
};