diff --git a/docs/journal.md b/docs/journal.md index d7786a4f37593b..d67c9404ff80f5 100644 --- a/docs/journal.md +++ b/docs/journal.md @@ -298,6 +298,7 @@ pageClass: routes 在 Stork 上注册并订阅关键词后,在 `我的` -> `关键词` 中可找到对应关键词的订阅 URL。URL 后的两个参数即为路由参数。 + ## X-MOL 平台 ### 期刊 diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 8d4d1ad9159f91..7f8f4dd838586d 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -837,6 +837,44 @@ Type 栏目: +## 衡阳全搜索 + +### 衡阳日报 + + + +| 版 | 编号 | +| ----------- | -- | +| 全部 | | +| 第 A01 版:版面一 | 1 | +| 第 A02 版:版面二 | 2 | +| 第 A03 版:版面三 | 3 | +| 第 A04 版:版面四 | 4 | +| 第 A05 版:版面五 | 5 | +| 第 A06 版:版面六 | 6 | +| 第 A07 版:版面七 | 7 | +| 第 A08 版:版面八 | 8 | + + + +### 衡阳晚报 + + + +| 版 | 编号 | +| ----------- | -- | +| 全部 | | +| 第 A01 版:版面一 | 1 | +| 第 A02 版:版面二 | 2 | +| 第 A03 版:版面三 | 3 | +| 第 A04 版:版面四 | 4 | +| 第 A05 版:版面五 | 5 | +| 第 A06 版:版面六 | 6 | +| 第 A07 版:版面七 | 7 | +| 第 A08 版:版面八 | 8 | + + + ## 华尔街见闻 ### 华尔街见闻 diff --git a/lib/v2/hyqss/index.js b/lib/v2/hyqss/index.js new file mode 100644 index 00000000000000..cba66931b7b7f4 --- /dev/null +++ b/lib/v2/hyqss/index.js @@ -0,0 +1,89 @@ +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 type = ctx.params.type ?? 'hyrb'; + const isDaily = type === 'hyrb'; + + const id = ctx.params.id; + + const rootUrl = 'http://epaper.hyqss.cn'; + const currentUrl = `${rootUrl}${isDaily ? '' : `/${type}`}`; + + let response = await got({ + method: 'get', + url: currentUrl, + }); + + const url = response.data.match(/URL=(.*)"/)[1]; + + response = await got({ + method: 'get', + url: `${currentUrl}/${id ? url.replace(/node_\d+\.htm/, `node_19${isDaily ? '62' : '74'}${id}.htm`) : url}`, + }); + + const $ = cheerio.load(response.data); + + const matches = url.match(/html\/(.*)\/node/); + const link = `${rootUrl}/${isDaily ? '' : 'hywb/'}html/${matches[1]}`; + + let items = $('#main-ed-articlenav-list') + .first() + .find('a') + .toArray() + .map((a) => `${link}/${$(a).attr('href')}`); + + if (!id) { + await Promise.all( + $('#bmdhTable') + .find('#pageLink') + .toArray() + .map((p) => `${link}/${$(p).attr('href')}`) + .map(async (p) => { + const pageResponse = await got({ + method: 'get', + url: p, + }); + + const page = cheerio.load(pageResponse.data); + + items.push( + ...page('#main-ed-articlenav-list') + .first() + .find('a') + .toArray() + .map((a) => `${link}/${page(a).attr('href')}`) + ); + }) + ); + } + + 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('.font01').text(), + description: content('#ozoom').html(), + pubDate: timezone(parseDate(matches[1], 'YYYY-MM/DD'), +8), + }; + }) + ) + ); + + ctx.state.data = { + title: `衡阳${isDaily ? '日' : '晚'}报${id ? ` - ${$('strong').first().parent().text()}` : ''}`, + link: currentUrl, + item: items, + allowEmpty: true, + }; +}; diff --git a/lib/v2/hyqss/maintainer.js b/lib/v2/hyqss/maintainer.js new file mode 100644 index 00000000000000..ca9e7a45244be6 --- /dev/null +++ b/lib/v2/hyqss/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/hyrb/:id?': ['nczitzk'], + '/hywb/:id?': ['nczitzk'], +}; diff --git a/lib/v2/hyqss/radar.js b/lib/v2/hyqss/radar.js new file mode 100644 index 00000000000000..2ee78b5ff90d9e --- /dev/null +++ b/lib/v2/hyqss/radar.js @@ -0,0 +1,22 @@ +const radars = [ + { + title: '衡阳日报', + docs: 'https://docs.rsshub.app/journal.html#heng-yang-quan-sou-suo-heng-yang-ri-bao', + source: ['/'], + target: '/hnrb/hyrb/:id?', + }, + { + title: '衡阳晚报', + docs: 'https://docs.rsshub.app/journal.html#heng-yang-quan-sou-suo-heng-yang-wan-bao', + source: ['/'], + target: '/hnrb/hywb/:id?', + }, +]; + +module.exports = { + 'hyqss.cn': { + _name: '衡阳全搜索', + '.': radars, + epaper: radars, + }, +}; diff --git a/lib/v2/hyqss/router.js b/lib/v2/hyqss/router.js new file mode 100644 index 00000000000000..5f136f299b1c03 --- /dev/null +++ b/lib/v2/hyqss/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:type?/:id?', require('./index')); +};