diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 3f6dbf713b5238..508a361b280e33 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -2451,6 +2451,18 @@ category 对应的关键词有 +## 浙江在线 + +### 浙报集团系列报刊 + + + +| 浙江日报 | 钱江晚报 | 美术报 | 浙江老年报 | 浙江法制报 | 江南游报 | +| ---- | ---- | --- | ----- | ----- | ---- | +| zjrb | qjwb | msb | zjlnb | zjfzb | jnyb | + + + ## 中国日报 ### 英语点津 diff --git a/lib/v2/zjol/maintainer.js b/lib/v2/zjol/maintainer.js new file mode 100644 index 00000000000000..f146840f72f871 --- /dev/null +++ b/lib/v2/zjol/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/paper/:id?': ['nczitzk'], +}; diff --git a/lib/v2/zjol/paper.js b/lib/v2/zjol/paper.js new file mode 100644 index 00000000000000..67126d0ebc77a0 --- /dev/null +++ b/lib/v2/zjol/paper.js @@ -0,0 +1,88 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const id = ctx.params.id ?? 'zjrb'; + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 100; + + const query = id === 'jnyb' ? 'map[name="PagePicMap"] area' : 'ul.main-ed-articlenav-list li a'; + + const rootUrl = id === 'qjwb' ? 'http://qjwb.thehour.cn' : `https://${id}.zjol.com.cn`; + let currentUrl = `${rootUrl}/paperindex.htm`; + + let response = await got({ + method: 'get', + url: currentUrl, + }); + + const url = response.data.match(/URL=(.*)"/)[1]; + const pubDate = parseDate(url.match(/(\d{4}-\d{2}\/\d{2})/)[1], 'YYYY-MM/DD'); + + currentUrl = `${rootUrl}/${url.replace(`/${url.split('/').pop()}`, '')}`; + + response = await got({ + method: 'get', + url: `${rootUrl}/${url}`, + }); + + const $ = cheerio.load(response.data); + + let items = $(query) + .toArray() + .map((a) => `${currentUrl}/${$(a).attr('href')}`); + + await Promise.all( + $('#pageLink') + .slice(1) + .toArray() + .map((p) => `${currentUrl}/${$(p).attr('href')}`) + .map(async (p) => { + const pageResponse = await got({ + method: 'get', + url: p, + }); + + const page = cheerio.load(pageResponse.data); + + items.push( + ...page(query) + .toArray() + .map((a) => `${currentUrl}/${page(a).attr('href')}`) + ); + }) + ); + + items = await Promise.all( + items + .filter((a) => (id === 'jnyb' ? /\?div=1$/.test(a) : true)) + .slice(0, limit) + .map((link) => + ctx.cache.tryGet(link, async () => { + const detailResponse = await got({ + method: 'get', + url: link, + }); + + const content = cheerio.load(detailResponse.data); + + const title = content('.main-article-title').text(); + + content('.main-article-alltitle').remove(); + + return { + title, + pubDate, + link: link.split('?')[0], + description: content('.main-article-content').html(), + }; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: rootUrl, + item: items, + }; +}; diff --git a/lib/v2/zjol/radar.js b/lib/v2/zjol/radar.js new file mode 100644 index 00000000000000..25ce162e254699 --- /dev/null +++ b/lib/v2/zjol/radar.js @@ -0,0 +1,61 @@ +module.exports = { + 'zjol.com.cn': { + _name: '浙江在线', + '.': [ + { + title: '浙报集团系列报刊', + docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan', + source: ['/'], + target: (params, url) => `/zjol/paper/${new URL(url).toString().match(/\/\/(.*?)\.zjol/)[1]}`, + }, + ], + zjrb: [ + { + title: '浙江日报', + docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan', + source: ['/'], + target: '/zjol/paper/zjrb', + }, + ], + qjwb: [ + { + title: '钱江晚报', + docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan', + source: ['/'], + target: '/zjol/paper/qjwb', + }, + ], + msb: [ + { + title: '美术报', + docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan', + source: ['/'], + target: '/zjol/paper/msb', + }, + ], + zjlnb: [ + { + title: '浙江老年报', + docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan', + source: ['/'], + target: '/zjol/paper/zjlnb', + }, + ], + zjfzb: [ + { + title: '浙江法制报', + docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan', + source: ['/'], + target: '/zjol/paper/zjfzb', + }, + ], + jnyb: [ + { + title: '江南游报', + docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan', + source: ['/'], + target: '/zjol/paper/jnyb', + }, + ], + }, +}; diff --git a/lib/v2/zjol/router.js b/lib/v2/zjol/router.js new file mode 100644 index 00000000000000..896721b6d87a8a --- /dev/null +++ b/lib/v2/zjol/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/paper/:id?', require('./paper')); +};