feat(route): guanhai (#11415)

This commit is contained in:
Tony
2022-12-08 23:08:05 +08:00
committed by GitHub
parent 081c3a08c7
commit 90d845504f
5 changed files with 73 additions and 0 deletions
+6
View File
@@ -2310,6 +2310,12 @@ others = 热点新闻 + 滚动新闻
<Route author="Jeason0228" example="/guancha/personalpage/243983" path="/guancha/personalpage/:uid" :paramsDesc="['用户id, 可在URL中找到']" />
## 观海新闻
### 首页
<Route author="TonyRL" example="/guanhai" path="/guanhai" radar="1" rssbud="1"/>
## 广告门
### 板块
+47
View File
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const { data: response } = await got('https://www.guanhai.com.cn');
const $ = cheerio.load(response);
const imgBox = $('.img-box');
const recommand = {
title: imgBox.find('a').first().attr('title'),
link: imgBox.find('a').first().attr('href'),
pubDate: timezone(parseDate(imgBox.find('time').text()), 8),
};
const list = $('.pic-summary .title')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('a').attr('title'),
link: item.find('a').attr('href'),
pubDate: timezone(parseDate(item.find('time').text()), 8),
};
})
.concat(recommand);
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
item.author = $('.source').text();
item.description = $('.article-content').html();
return item;
})
)
);
ctx.state.data = {
title: $('head title').text(),
description: $('head meta[name=description]').text(),
image: 'https://www.guanhai.com.cn/favicon.ico',
link: 'https://www.guanhai.com.cn',
item: items,
};
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'': ['TonyRL'],
'/': ['TonyRL'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'guanhai.com.cn': {
_name: '观海新闻',
'.': [
{
title: '首页',
docs: 'https://docs.rsshub.app/new-media.html#guan-hai-xin-wen',
source: ['/'],
target: '/guanhai',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/', require('./index'));
};