From 31aaf4ed0d211cfd49b88e6d725d48d508efe884 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Sat, 18 Jun 2022 11:45:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E5=98=89=E5=85=B4=E6=97=A5?= =?UTF-8?q?=E6=8A=A5=20&=20=E5=8D=97=E6=B9=96=E6=99=9A=E6=8A=A5=20(#9979)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/traditional-media.md | 50 +++++++++++++ lib/v2/cnjxol/index.js | 94 +++++++++++++++++++++++++ lib/v2/cnjxol/maintainer.js | 4 ++ lib/v2/cnjxol/radar.js | 19 +++++ lib/v2/cnjxol/router.js | 3 + lib/v2/cnjxol/templates/description.art | 2 + 6 files changed, 172 insertions(+) create mode 100644 lib/v2/cnjxol/index.js create mode 100644 lib/v2/cnjxol/maintainer.js create mode 100644 lib/v2/cnjxol/radar.js create mode 100644 lib/v2/cnjxol/router.js create mode 100644 lib/v2/cnjxol/templates/description.art diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 37025c648..0efc09ee8 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1278,6 +1278,56 @@ category 对应的关键词有 +## 南湖清风 + +### 嘉兴日报 + + + +| 版 | 编号 | +| ------------ | -- | +| 全部 | | +| 第 01 版:要闻 | 01 | +| 第 02 版:要闻 | 02 | +| 第 03 版:要闻 | 03 | +| 第 04 版:嘉一度 | 04 | +| 第 05 版:聚焦 | 05 | +| 第 06 版:党报热线 | 06 | +| 第 07 版:天下 | 07 | +| 第 08 版:聚焦 | 08 | +| 第 09 版:南湖新闻 | 09 | +| 第 10 版:综合 | 10 | +| 第 11 版:梅花洲 | 11 | +| 第 12 版:南湖纵横 | 12 | +| 第 13 版:秀洲新闻 | 13 | +| 第 14 版:综合 | 14 | +| 第 15 版:秀・观察 | 15 | +| 第 16 版:走进高新区 | 16 | + + + +### 南湖晚报 + + + +| 版 | 编号 | +| -------------------- | -- | +| 全部 | | +| 第 01 版:要闻 | 01 | +| 第 02 版:品质嘉兴・红船旁的美丽城镇 | 02 | +| 第 03 版:嘉兴新闻 | 03 | +| 第 04 版:嘉兴新闻 | 04 | +| 第 05 版:今日聚焦 | 05 | +| 第 06 版:嘉兴新闻 | 06 | +| 第 07 版:热线新闻 | 07 | +| 第 08 版:财经新闻 | 08 | +| 第 09 版:热线新闻 | 09 | +| 第 10 版:公益广告 | 10 | +| 第 11 版:消费周刊 | 11 | +| 第 12 版:悦读坊 | 12 | + + + ## 南华早报 SCMP ### 新闻 diff --git a/lib/v2/cnjxol/index.js b/lib/v2/cnjxol/index.js new file mode 100644 index 000000000..ec13c0120 --- /dev/null +++ b/lib/v2/cnjxol/index.js @@ -0,0 +1,94 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +const categories = { + jxrb: '嘉兴日报', + nhwb: '南湖晚报', +}; + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'jxrb'; + const id = ctx.params.id; + + const rootUrl = `https://${category}.cnjxol.com`; + const currentUrl = `${rootUrl}/${category}Paper/pc/layout`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + let $ = cheerio.load(response.data); + const dateMatch = $('a') + .first() + .attr('href') + .match(/\d{6}\/\d{2}/)[0]; + + let items = []; + + if (id) { + const pageUrl = `${currentUrl}/${dateMatch}/node_${id}.html`; + + const pageResponse = await got({ + method: 'get', + url: pageUrl, + }); + + $ = cheerio.load(pageResponse.data); + + items = $('#articlelist .clearfix a') + .toArray() + .map((a) => `${currentUrl}/${$(a).attr('href')}`.replace(/layout\/\.\.\/\.\.\/\.\.\//g, '')); + } else { + await Promise.all( + $('#list li a') + .toArray() + .map(async (p) => { + const pageResponse = await got({ + method: 'get', + url: `${currentUrl}/${$(p).attr('href')}`, + }); + + const page = cheerio.load(pageResponse.data); + + items.push( + ...page('#articlelist .clearfix a') + .toArray() + .map((a) => `${currentUrl}/${page(a).attr('href')}`.replace(/layout\/\.\.\/\.\.\/\.\.\//g, '')) + ); + }) + ); + } + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item, async () => { + const detailResponse = await got({ + method: 'get', + url: item, + }); + + const content = cheerio.load(detailResponse.data); + + return { + link: item, + title: content('#Title').text(), + pubDate: parseDate(content('date').text()), + description: art(path.join(__dirname, 'templates/description.art'), { + attachment: content('.attachment').html(), + content: content('founder-content').html(), + }), + }; + }) + ) + ); + + ctx.state.data = { + title: `${categories[category]}${id ? ` - ${$('#layout').text()}` : ''}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/cnjxol/maintainer.js b/lib/v2/cnjxol/maintainer.js new file mode 100644 index 000000000..9b7bd1c03 --- /dev/null +++ b/lib/v2/cnjxol/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/jxrb/:id?': ['nczitzk'], + '/nhwb/:id?': ['nczitzk'], +}; diff --git a/lib/v2/cnjxol/radar.js b/lib/v2/cnjxol/radar.js new file mode 100644 index 000000000..6d706c626 --- /dev/null +++ b/lib/v2/cnjxol/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'cnjxol.com': { + _name: '南湖清风', + '.': [ + { + title: '嘉兴日报', + docs: 'https://docs.rsshub.app/traditional-media.html#nan-hu-qing-feng-jia-xing-ri-bao', + source: ['/'], + target: '/cnjxol/jxrb/:id', + }, + { + title: '南湖晚报', + docs: 'https://docs.rsshub.app/traditional-media.html#nan-hu-qing-feng-nan-hu-wan-bao', + source: ['/'], + target: '/cnjxol/nhwb/:id', + }, + ], + }, +}; diff --git a/lib/v2/cnjxol/router.js b/lib/v2/cnjxol/router.js new file mode 100644 index 000000000..3ceee154c --- /dev/null +++ b/lib/v2/cnjxol/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?/:id?', require('./index')); +}; diff --git a/lib/v2/cnjxol/templates/description.art b/lib/v2/cnjxol/templates/description.art new file mode 100644 index 000000000..80ea21796 --- /dev/null +++ b/lib/v2/cnjxol/templates/description.art @@ -0,0 +1,2 @@ +{{@ attachment }} +{{@ content }} \ No newline at end of file