From cf6dff4305e2a6cde016bfe34493b72affb05fc2 Mon Sep 17 00:00:00 2001 From: drgnchan <40224023+drgnchan@users.noreply.github.com> Date: Sat, 21 Jan 2023 01:06:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E'=E8=A7=82=E7=82=B9?= =?UTF-8?q?=E7=BD=91'=20(#11658)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 新增'观点网' * polish --- docs/new-media.md | 6 ++++++ lib/v2/guandian/index.js | 37 +++++++++++++++++++++++++++++++++++ lib/v2/guandian/maintainer.js | 3 +++ lib/v2/guandian/radar.js | 11 +++++++++++ lib/v2/guandian/router.js | 3 +++ 5 files changed, 60 insertions(+) create mode 100644 lib/v2/guandian/index.js create mode 100644 lib/v2/guandian/maintainer.js create mode 100644 lib/v2/guandian/radar.js create mode 100644 lib/v2/guandian/router.js diff --git a/docs/new-media.md b/docs/new-media.md index e0db8a10a1..ce66dc72ea 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2318,6 +2318,12 @@ others = 热点新闻 + 滚动新闻 +## 观点网 + +### 资讯 + + + ## 观海新闻 ### 首页 diff --git a/lib/v2/guandian/index.js b/lib/v2/guandian/index.js new file mode 100644 index 0000000000..9697e23189 --- /dev/null +++ b/lib/v2/guandian/index.js @@ -0,0 +1,37 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const baseUrl = 'https://www.guandian.cn'; + +module.exports = async (ctx) => { + const cat = ctx.params.category; + const reqUrl = `${baseUrl}/${cat}/`; + const response = await got(reqUrl); + const $ = cheerio.load(response.data); + + const items = $('.con_l li') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('.con_l_con_r a'); + const link = a.attr('href'); + const title = a.find('h3').text(); + const desc = item.find('.con_l_con_r p').text(); + + const dateStr = item.find('#keyword span').text(); + return { + title, + link, + description: desc, + pubDate: timezone(parseDate(dateStr), 8), + }; + }); + + ctx.state.data = { + title: $('head title').text(), + link: reqUrl, + item: items, + }; +}; diff --git a/lib/v2/guandian/maintainer.js b/lib/v2/guandian/maintainer.js new file mode 100644 index 0000000000..41b9175da3 --- /dev/null +++ b/lib/v2/guandian/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category': ['drgnchan'], +}; diff --git a/lib/v2/guandian/radar.js b/lib/v2/guandian/radar.js new file mode 100644 index 0000000000..e22627bfc4 --- /dev/null +++ b/lib/v2/guandian/radar.js @@ -0,0 +1,11 @@ +module.exports = { + 'guandian.cn': { + _name: '观点网', + www: { + title: '资讯', + docs: 'https://docs.rsshub.app/new-media.html#guan-dian-wang-zi-xun', + source: ['/:category'], + target: '/guandian/:category', + }, + }, +}; diff --git a/lib/v2/guandian/router.js b/lib/v2/guandian/router.js new file mode 100644 index 0000000000..a539e13364 --- /dev/null +++ b/lib/v2/guandian/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category', require('./index')); +};