feat(route): add 网易新闻今日关注 (#8731)
This commit is contained in:
parent
c95762af47
commit
9bbc3c2c31
|
|
@ -2886,6 +2886,18 @@ column 为 third 时可选的 category:
|
|||
|
||||
## 网易新闻
|
||||
|
||||
### 今日关注
|
||||
|
||||
<Route author="nczitzk" example="/netease/today" path="/netease/today/:need_content?" :paramsDesc="['需要获取全文,填写 true/yes 表示需要,默认需要']">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
参数 **需要获取全文** 设置为 `true` `yes` `t` `y` 等值后,RSS 会携带该新闻条目的对应全文。
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
### 排行榜
|
||||
|
||||
<Route author="nczitzk" example="/netease/news/rank/whole/click/day" path="/netease/news/rank/:category?/:type?/:time?" :paramsDesc="['新闻分类,参见下表,默认为“全站”','排行榜类型,“点击榜”对应`click`,“跟贴榜”对应`follow`,默认为“点击榜”','统计时间,“1小时”对应`hour`,“24小时”对应`day`,“本周”对应`week`,“本月”对应`month`,默认为“24小时”']">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = {
|
||||
'/renjian/:category?': ['nczitzk'],
|
||||
'/today/:need_content?': ['nczitzk'],
|
||||
'/news/rank/:category?/:type?/:time?': ['nczitzk'],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,9 +12,17 @@ module.exports = {
|
|||
news: [
|
||||
{
|
||||
title: '排行榜',
|
||||
docs: 'https://docs.rsshub.app/.html#',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#wang-yi-xin-wen-pai-hang-bang',
|
||||
source: ['/:category', '/'],
|
||||
target: '//:category?',
|
||||
target: '/netease/news/rank/:category?/:type?/:time?',
|
||||
},
|
||||
],
|
||||
m: [
|
||||
{
|
||||
title: '今日关注',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#wang-yi-xin-wen-jin-ri-guan-zhu',
|
||||
source: ['/'],
|
||||
target: '/netease/today/:need_content?',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/renjian/:category?', require('./renjian'));
|
||||
router.get('/today/:need_content?', require('./today'));
|
||||
router.get('/news/rank/:category?/:type?/:time?', require('./rank'));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const needContent = /t|y/i.test(ctx.params.need_content ?? 'true');
|
||||
|
||||
const rootUrl = 'https://gw.m.163.com';
|
||||
const currentUrl = `${rootUrl}/nc/api/v1/feed/static/normal-list?start=0&tid=T1573700340788&size=${ctx.query.limit ?? (needContent ? 30 : 200)}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
let items = response.data.data.items.map((item) => ({
|
||||
title: item.title,
|
||||
author: item.source,
|
||||
pubDate: timezone(parseDate(item.ptime), +8),
|
||||
description: `<p>${item.digest}</p><img src="${item.imgsrc}">`,
|
||||
link: item.url || `https://c.m.163.com/news/a/${item.docid}.html`,
|
||||
}));
|
||||
|
||||
if (needContent) {
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('.bot_word').remove();
|
||||
|
||||
content('figure[data-echo]').each(function () {
|
||||
content(this).html(`<img src="${content(this).attr('data-echo')}">`);
|
||||
});
|
||||
|
||||
item.description = content('.content, article').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: '今日关注 - 网易新闻',
|
||||
link: 'https://wp.m.163.com/163/html/newsapp/todayFocus/index.html',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue