diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 128c4a775..ab639f15f 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1985,6 +1985,12 @@ category 对应的关键词有 +## 星島日報 + +### 即時 + + + ## 星洲网 ### 首页 diff --git a/lib/v2/stheadline/maintainer.js b/lib/v2/stheadline/maintainer.js new file mode 100644 index 000000000..46206e7f3 --- /dev/null +++ b/lib/v2/stheadline/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/std/realtime/:category*': ['TonyRL'], +}; diff --git a/lib/v2/stheadline/radar.js b/lib/v2/stheadline/radar.js new file mode 100644 index 000000000..bfdc2be3b --- /dev/null +++ b/lib/v2/stheadline/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'stheadline.com': { + _name: '星島日報', + std: [ + { + title: '即時', + docs: 'https://docs.rsshub.app/traditional-media.html#xing-dao-ri-bao', + source: ['/realtime/*category'], + target: (params) => `/stdheadline/std/realtime/${params.category}`, + }, + ], + }, +}; diff --git a/lib/v2/stheadline/router.js b/lib/v2/stheadline/router.js new file mode 100644 index 000000000..ee345be8b --- /dev/null +++ b/lib/v2/stheadline/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/std/realtime/:category*', require('./std/realtime')); +}; diff --git a/lib/v2/stheadline/std/realtime.js b/lib/v2/stheadline/std/realtime.js new file mode 100644 index 000000000..2fea18068 --- /dev/null +++ b/lib/v2/stheadline/std/realtime.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const baseUrl = 'https://std.stheadline.com'; + +module.exports = async (ctx) => { + const { category = '即時' } = ctx.params; + const url = `${baseUrl}/realtime/${category}`; + const { data: response } = await got(url); + const $ = cheerio.load(response); + + const items = $('.col-md-9 .media-body .h5 a') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.attr('title'), + link: item.attr('href'), + guid: item.attr('href').substring(0, item.attr('href').lastIndexOf('/')), + }; + }); + + await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + + item.description = $('.paragraphs').html(); + item.pubDate = timezone(parseDate($('.content .date').text())); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + description: $('meta[name=description]').attr('content'), + image: 'https://std.stheadline.com/dist/images/favicon/icon-512.png', + link: url, + item: items, + }; +};