diff --git a/docs/new-media.md b/docs/new-media.md index bf04cdd69..60eb4e1d2 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -4092,6 +4092,18 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/ +## 壹蘋新聞網 + +### 最新新聞 + + + +| 最新 | 娛樂 | 生活 | 社會 | 政治 | 國際 | 財經 | 飲食旅遊 | 房市 | 時尚 | 車市 | 健康 | 體育 | 3C | +| --- | ------------- | ---- | ----- | -------- | ------------- | ------- | --------- | -------- | ------- | ---- | ------ | ------ | ------ | +| new | entertainment | life | local | politics | international | finance | lifestyle | property | fashion | auto | health | sports | gadget | + + + ## 移动支付网 ### 新闻 diff --git a/lib/v2/nextapple/maintainer.js b/lib/v2/nextapple/maintainer.js new file mode 100644 index 000000000..e32416c24 --- /dev/null +++ b/lib/v2/nextapple/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/realtime/:category?': ['miles170'], +}; diff --git a/lib/v2/nextapple/radar.js b/lib/v2/nextapple/radar.js new file mode 100644 index 000000000..413f17f8b --- /dev/null +++ b/lib/v2/nextapple/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'nextapple.com': { + _name: '壹蘋新聞網', + tw: [ + { + title: '最新新聞', + docs: 'https://docs.rsshub.app/new-media.html#yi-ping-xin-wen-wang', + source: ['/', '/realtime/:category'], + target: '/nextapple/realtime/:category?', + }, + ], + }, +}; diff --git a/lib/v2/nextapple/realtime.js b/lib/v2/nextapple/realtime.js new file mode 100644 index 000000000..70712d3ec --- /dev/null +++ b/lib/v2/nextapple/realtime.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'new'; + const currentUrl = `https://tw.nextapple.com/realtime/${category}`; + const response = await got(currentUrl); + const $ = cheerio.load(response.data); + const items = await Promise.all( + $('article') + .get() + .map((item) => { + const link = $(item).find('.post-title').attr('href'); + return ctx.cache.tryGet(link, async () => { + const response = await got(link); + const $ = cheerio.load(response.data); + const mainContent = $('#main-content'); + const titleElement = mainContent.find('header h1'); + const title = titleElement.text(); + titleElement.remove(); + const postMetaElement = mainContent.find('.post-meta'); + const category = postMetaElement.find('.category').text(); + const pubDate = parseDate(postMetaElement.find('time').attr('datetime')); + postMetaElement.remove(); + $('.post-comments').remove(); + + return { + title, + description: mainContent.html(), + category, + pubDate, + link, + }; + }); + }) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/nextapple/router.js b/lib/v2/nextapple/router.js new file mode 100644 index 000000000..f330ccefa --- /dev/null +++ b/lib/v2/nextapple/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/realtime/:category?', require('./realtime')); +};