diff --git a/docs/new-media.md b/docs/new-media.md index 820ae0b90..4ced5b4a8 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2874,6 +2874,26 @@ column 为 third 时可选的 category: +## 風傳媒 + +### 分类 + + + +| 新聞總覽 | 地方新聞 | 歷史頻道 | 評論總覽 | +| -------- | ------------- | -------- | ----------- | +| articles | localarticles | history | all-comment | + +::: tip 提示 + +支持形如 的路由,即 [`/storm/category/118`](https://rsshub.app/storm/category/118) + +支持形如 的路由,即 [`/storm/localarticle-category/s149845`](https://rsshub.app/storm/localarticle-category/s149845) + +::: + + + ## 通識・現代中國 ### 議題熱話 diff --git a/lib/v2/storm/index.js b/lib/v2/storm/index.js new file mode 100644 index 000000000..b1242f242 --- /dev/null +++ b/lib/v2/storm/index.js @@ -0,0 +1,57 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'articles'; + const id = ctx.params.id ?? ''; + + const rootUrl = 'https://www.storm.mg'; + const currentUrl = `${rootUrl}/${category}${id ? `/${id}` : ''}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.link_title') + .map((_, item) => { + item = $(item); + + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('.notify_wordings').remove(); + content('#premium_block').remove(); + + item.description = content('#CMS_wrapper').html(); + item.author = content('meta[property="dable:author"]').attr('content'); + item.pubDate = parseDate(content('meta[itemprop="datePublished"]').attr('content')); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/storm/maintainer.js b/lib/v2/storm/maintainer.js new file mode 100644 index 000000000..e1e404c03 --- /dev/null +++ b/lib/v2/storm/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?/:id?': ['nczitzk'], +}; diff --git a/lib/v2/storm/radar.js b/lib/v2/storm/radar.js new file mode 100644 index 000000000..b019211e1 --- /dev/null +++ b/lib/v2/storm/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'storm.mg': { + _name: '風傳媒', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#feng-chuan-mei', + source: ['/:category/:id'], + target: '/storm/:category?/:id?', + }, + ], + }, +}; diff --git a/lib/v2/storm/router.js b/lib/v2/storm/router.js new file mode 100644 index 000000000..3ceee154c --- /dev/null +++ b/lib/v2/storm/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?/:id?', require('./index')); +};