feat(route): 封面新闻 (#9587)

* feat(route): 封面

* Update docs/new-media.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/thecover/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/thecover/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

Co-authored-by: yuxinliu <yuxin2@mgtv.com>
Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
yuxinliu-alex 2022-04-21 18:59:58 +08:00 committed by GitHub
parent 35347a921d
commit 04206ca5b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 97 additions and 0 deletions

View File

@ -1837,6 +1837,18 @@ area 分区选项
| --- | ----- |
| doc | video |
## 封面新闻
### 频道
<Route author="yuxinliu-alex" example="/thecover/channel/3560" path="/thecover/channel/:id?" :paramsDesc="['对应id,可在频道链接中获取默认为3892']">
| 天下 | 四川 | 辟谣 | 国际 | 云招考 | 30秒 | 拍客 | 体育 | 国内 | 帮扶铁军 | 文娱 | 宽窄 | 商业 | 千面 | 封面号 |
| ---- | ---- | ---- | ---- | -- | ---- | ---- | ---- | - | ---- | -- | -- | - | -- | -- |
| 3892 | 3560 | 3909 | 3686 | 11 | 3902 | 3889 | 3689 | 1 | 4002 | 12 | 46 | 4 | 21 | 17 |
</Route>
## 福利年
### 文章

View File

@ -0,0 +1,66 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const rootUrl = 'https://www.thecover.cn';
const nodes = {
3892: '天下',
3560: '四川',
3909: '辟谣',
3686: '国际',
11: '云招考',
3902: '30秒',
3889: '拍客',
3689: '体育',
1: '国内',
4002: '帮扶铁军',
12: '文娱',
46: '宽窄',
4: '商业',
21: '千面',
17: '封面号',
};
module.exports = async (ctx) => {
const id = ctx.params.id ?? '3892';
const targetUrl = rootUrl.concat(`/channel_${id}`);
const resp = await got({
method: 'get',
url: targetUrl,
});
const $ = cheerio.load(resp.data);
const list = $('a.link-to-article')
.filter(function () {
return $(this).attr('href').startsWith('/');
})
.map((_, item) => ({
link: rootUrl.concat($(item).attr('href')),
}))
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.title = content('h1', '.main-article').text();
item.description = content('section.article-content').html();
const info = content('span', '.props-of-title');
item.author = info.eq(0).text();
item.pubDate = timezone(parseDate(info.eq(1).text(), 'YYYY-MM-DD HH:mm'), +8);
return item;
})
)
);
ctx.state.data = {
title: `${nodes[id]}-封面新闻`,
link: targetUrl,
description: `封面新闻作为华西都市报深度融合转型和打造新型主流媒体的载体牢固确立移动优先战略创新移动新闻产品打造移动传播矩阵封面新闻的传播力、引导力、影响力和公信力不断得到各方肯定。封面新闻突破千万的用户下载量呈现出以四川为主阵地的全国分布态势用户年龄构成以20-35岁为主“亿万年轻人的生活方式”的定位初步得到体现。`,
language: 'zh-cn',
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/channel/:id?': ['yuxinliu-alex'],
};

13
lib/v2/thecover/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'thecover.cn': {
_name: '封面新闻',
'.': [
{
title: '频道',
docs: 'https://docs.rsshub.app/new-media.html#the-cover',
source: ['/:id', '/'],
target: (params) => `/thecover/channel/${params.id.replace('channel_', '')}`,
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/channel/:id?', require('./channel'));
};