Skip to content

Commit 90d8455

Browse files
authored
feat(route): guanhai (DIYgod#11415)
1 parent 081c3a0 commit 90d8455

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

docs/new-media.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,12 @@ others = 热点新闻 + 滚动新闻
23102310

23112311
<Route author="Jeason0228" example="/guancha/personalpage/243983" path="/guancha/personalpage/:uid" :paramsDesc="['用户id, 可在URL中找到']" />
23122312

2313+
## 观海新闻
2314+
2315+
### 首页
2316+
2317+
<Route author="TonyRL" example="/guanhai" path="/guanhai" radar="1" rssbud="1"/>
2318+
23132319
## 广告门
23142320

23152321
### 板块

lib/v2/guanhai/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const got = require('@/utils/got');
2+
const cheerio = require('cheerio');
3+
const { parseDate } = require('@/utils/parse-date');
4+
const timezone = require('@/utils/timezone');
5+
6+
module.exports = async (ctx) => {
7+
const { data: response } = await got('https://www.guanhai.com.cn');
8+
const $ = cheerio.load(response);
9+
10+
const imgBox = $('.img-box');
11+
const recommand = {
12+
title: imgBox.find('a').first().attr('title'),
13+
link: imgBox.find('a').first().attr('href'),
14+
pubDate: timezone(parseDate(imgBox.find('time').text()), 8),
15+
};
16+
const list = $('.pic-summary .title')
17+
.toArray()
18+
.map((item) => {
19+
item = $(item);
20+
return {
21+
title: item.find('a').attr('title'),
22+
link: item.find('a').attr('href'),
23+
pubDate: timezone(parseDate(item.find('time').text()), 8),
24+
};
25+
})
26+
.concat(recommand);
27+
28+
const items = await Promise.all(
29+
list.map((item) =>
30+
ctx.cache.tryGet(item.link, async () => {
31+
const { data: response } = await got(item.link);
32+
const $ = cheerio.load(response);
33+
item.author = $('.source').text();
34+
item.description = $('.article-content').html();
35+
return item;
36+
})
37+
)
38+
);
39+
40+
ctx.state.data = {
41+
title: $('head title').text(),
42+
description: $('head meta[name=description]').text(),
43+
image: 'https://www.guanhai.com.cn/favicon.ico',
44+
link: 'https://www.guanhai.com.cn',
45+
item: items,
46+
};
47+
};

lib/v2/guanhai/maintainer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
'': ['TonyRL'],
3+
'/': ['TonyRL'],
4+
};

lib/v2/guanhai/radar.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
'guanhai.com.cn': {
3+
_name: '观海新闻',
4+
'.': [
5+
{
6+
title: '首页',
7+
docs: 'https://docs.rsshub.app/new-media.html#guan-hai-xin-wen',
8+
source: ['/'],
9+
target: '/guanhai',
10+
},
11+
],
12+
},
13+
};

lib/v2/guanhai/router.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = (router) => {
2+
router.get('/', require('./index'));
3+
};

0 commit comments

Comments
 (0)