From 90d845504ff39a0a34a933452b71fa12e91e67e7 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 8 Dec 2022 09:08:05 -0600 Subject: [PATCH] feat(route): guanhai (#11415) --- docs/new-media.md | 6 +++++ lib/v2/guanhai/index.js | 47 ++++++++++++++++++++++++++++++++++++ lib/v2/guanhai/maintainer.js | 4 +++ lib/v2/guanhai/radar.js | 13 ++++++++++ lib/v2/guanhai/router.js | 3 +++ 5 files changed, 73 insertions(+) create mode 100644 lib/v2/guanhai/index.js create mode 100644 lib/v2/guanhai/maintainer.js create mode 100644 lib/v2/guanhai/radar.js create mode 100644 lib/v2/guanhai/router.js diff --git a/docs/new-media.md b/docs/new-media.md index a5140ffbe..46f9a7cc1 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2310,6 +2310,12 @@ others = 热点新闻 + 滚动新闻 +## 观海新闻 + +### 首页 + + + ## 广告门 ### 板块 diff --git a/lib/v2/guanhai/index.js b/lib/v2/guanhai/index.js new file mode 100644 index 000000000..99136361f --- /dev/null +++ b/lib/v2/guanhai/index.js @@ -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, + }; +}; diff --git a/lib/v2/guanhai/maintainer.js b/lib/v2/guanhai/maintainer.js new file mode 100644 index 000000000..13972819d --- /dev/null +++ b/lib/v2/guanhai/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '': ['TonyRL'], + '/': ['TonyRL'], +}; diff --git a/lib/v2/guanhai/radar.js b/lib/v2/guanhai/radar.js new file mode 100644 index 000000000..3fc4015e6 --- /dev/null +++ b/lib/v2/guanhai/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/guanhai/router.js b/lib/v2/guanhai/router.js new file mode 100644 index 000000000..7e427447c --- /dev/null +++ b/lib/v2/guanhai/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/', require('./index')); +};