From dd1fcefbf02a85af0eca5187cf655d56a6a5e9b6 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Fri, 24 Nov 2023 00:25:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8E=A6=E9=97=A8?= =?UTF-8?q?=E7=BD=91=E6=96=B0=E9=97=BB=20(#13868)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 厦门网新闻 * fix url --- lib/v2/xmnn/docs.js | 0 lib/v2/xmnn/maintainer.js | 1 + lib/v2/xmnn/news.js | 65 ++++++++++++++++++++++ lib/v2/xmnn/radar.js | 68 ++++++++++++++++++++++- lib/v2/xmnn/router.js | 1 + website/docs/routes/traditional-media.mdx | 20 ++++++- 6 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 lib/v2/xmnn/docs.js create mode 100644 lib/v2/xmnn/news.js diff --git a/lib/v2/xmnn/docs.js b/lib/v2/xmnn/docs.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/v2/xmnn/maintainer.js b/lib/v2/xmnn/maintainer.js index 923626b6f8..927757f618 100644 --- a/lib/v2/xmnn/maintainer.js +++ b/lib/v2/xmnn/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/epaper/:id?': ['nczitzk'], + '/news/:category?': ['nczitzk'], }; diff --git a/lib/v2/xmnn/news.js b/lib/v2/xmnn/news.js new file mode 100644 index 0000000000..fecdca40cd --- /dev/null +++ b/lib/v2/xmnn/news.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { category = 'xmxw' } = ctx.params; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30; + + const rootUrl = 'https://news.xmnn.cn'; + const currentUrl = new URL(`${category}/`, rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = cheerio.load(response); + + let items = $('div#sort_body ul li a') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.find('h1').text().trim(), + link: item.prop('href'), + description: item.find('div.abstract').html(), + author: item.find('div.source').text(), + pubDate: timezone(parseDate(item.find('div.time').text()), +8), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link); + + const content = cheerio.load(detailResponse); + + item.title = content('div.cont-h, div.tip h1').text().trim(); + item.description = content('div.TRS_Editor').html(); + item.author = content('span.cont-a-src a') + .toArray() + .map((a) => content(a).text()); + item.pubDate = timezone(parseDate(content('span.time, div.pubtime div.w').contents().first().text().trim()), +8); + + return item; + }) + ) + ); + + const title = $('title').text(); + const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; + + ctx.state.data = { + item: items, + title, + link: currentUrl, + description: $('meta[name="description"]').prop('content'), + language: 'zh', + icon, + logo: icon, + subtitle: $('div.h').text(), + author: title.split(/_/).pop(), + }; +}; diff --git a/lib/v2/xmnn/radar.js b/lib/v2/xmnn/radar.js index 4483d7f687..0d916d3abc 100644 --- a/lib/v2/xmnn/radar.js +++ b/lib/v2/xmnn/radar.js @@ -5,9 +5,75 @@ module.exports = { { title: '数字媒体', docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-shu-zi-mei-ti', - source: ['/:id', '/'], + source: ['/:id'], target: '/xmnn/epaper/:id', }, ], + news: [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen', + source: ['/:category*'], + target: (params) => { + const category = params.category; + + return `/xmnn/news/${category ? `/${category}` : ''}`; + }, + }, + { + title: '厦门新闻发布', + docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen', + source: ['/xmxwfb'], + target: '/xmnn/news/xmxwfb', + }, + { + title: '厦门新闻', + docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen', + source: ['/xmxw'], + target: '/xmnn/news/xmxw', + }, + { + title: '本网快报', + docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen', + source: ['/bwkb'], + target: '/xmnn/news/bwkb', + }, + { + title: '厦门网眼', + docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen', + source: ['/xmwy'], + target: '/xmnn/news/xmwy', + }, + { + title: '福建新闻', + docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen', + source: ['/fjxw'], + target: '/xmnn/news/fjxw', + }, + { + title: '国内新闻', + docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen', + source: ['/gnxw'], + target: '/xmnn/news/gnxw', + }, + { + title: '国际新闻', + docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen', + source: ['/gjxw'], + target: '/xmnn/news/gjxw', + }, + { + title: '台海新闻', + docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen', + source: ['/thxw'], + target: '/xmnn/news/thxw', + }, + { + title: '社会新闻', + docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen', + source: ['/shxw'], + target: '/xmnn/news/shxw', + }, + ], }, }; diff --git a/lib/v2/xmnn/router.js b/lib/v2/xmnn/router.js index bf36378cc2..6e5be488d7 100644 --- a/lib/v2/xmnn/router.js +++ b/lib/v2/xmnn/router.js @@ -1,3 +1,4 @@ module.exports = function (router) { router.get('/epaper/:id?', require('./epaper')); + router.get('/news/:category*', require('./news')); }; diff --git a/website/docs/routes/traditional-media.mdx b/website/docs/routes/traditional-media.mdx index 8b6cbf7502..76693ba49f 100644 --- a/website/docs/routes/traditional-media.mdx +++ b/website/docs/routes/traditional-media.mdx @@ -2302,7 +2302,7 @@ category 对应的关键词有 ### 数字媒体 {#xia-men-wang-shu-zi-mei-ti} - + | 厦门日报 | 厦门晚报 | 海西晨报 | 城市捷报 | | -------- | -------- | -------- | -------- | @@ -2310,6 +2310,24 @@ category 对应的关键词有 +### 新闻 {#xia-men-wang-xin-wen} + + + +| 分类名 | 分类 id | +| ------------ | ------- | +| 厦门新闻发布 | xmxwfb | +| 厦门新闻 | xmxw | +| 本网快报 | bwkb | +| 厦门网眼 | xmwy | +| 福建新闻 | fjxw | +| 国内新闻 | gnxw | +| 国际新闻 | gjxw | +| 台海新闻 | thxw | +| 社会新闻 | shxw | + + + ## 四川广播电视台 {#si-chuan-guang-bo-dian-shi-tai} ### 电视回放 {#si-chuan-guang-bo-dian-shi-tai-dian-shi-hui-fang}