diff --git a/docs/traditional-media.md b/docs/traditional-media.md index a67bbbe00e..10c6b7cfa7 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1110,6 +1110,18 @@ category 对应的关键词有 +## 苹果新闻网 + + + +频道参数均可在官网获取,如: + +`https://tw.appledaily.com/realtime/micromovie/` 对应 `/appledaily/micromovie` + +`https://tw.appledaily.com/home/` 对应 `/appledaily/home` + + + ## 齐鲁晚报 ### 新闻 diff --git a/lib/v2/appledaily/index.js b/lib/v2/appledaily/index.js new file mode 100644 index 0000000000..f7ccc70d43 --- /dev/null +++ b/lib/v2/appledaily/index.js @@ -0,0 +1,69 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const path = require('path'); +const { art } = require('@/utils/render'); + +const rootUrl = 'https://tw.appledaily.com'; + +const channelMap = { + home: '首頁', + recommend: '焦点', + new: '最新', + hot: '热门', + life: '生活', + entertainment: '娱乐', + local: '社会', + property: '财经地产', + international: '国际', + politics: '政治', + gadget: '3C车城', + supplement: '吃喝玩乐', + sports: '体育', + forum: '苹评理', + micromovie: '微视频', +}; + +module.exports = async (ctx) => { + const channel = ctx.params.channel ?? 'home'; + const url = `${rootUrl}${channel === 'home' ? '/home' : `/realtime/${channel}`}`; + + const response = await got.get(url); + const $ = cheerio.load(response.data); + const list = $('div.flex-feature') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 25) + .map((_, item) => { + const title = $(item).find('span.headline').text(); + const link = rootUrl + $(item).find('a').attr('href'); + const pubDate = parseDate($(item).find('div.timestamp').text(), 'YYYY/MM/DD HH:mm'); + + return { + title, + link, + pubDate, + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got.get(item.link); + const content = cheerio.load(detailResponse.data); + const dataJs = content('script#fusion-metadata').html(); + const descDataJSON = JSON.parse(dataJs.match(/Fusion.globalContent=(.*);Fusion.globalConte/)[1]); + item.description = art(path.join(__dirname, 'templates/content.art'), { + content_elements: descDataJSON.content_elements, + }); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `蘋果日報 - ${channelMap[channel]}`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/appledaily/maintainer.js b/lib/v2/appledaily/maintainer.js new file mode 100644 index 0000000000..27645c3d78 --- /dev/null +++ b/lib/v2/appledaily/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:channel?': ['Fatpandac'], +}; diff --git a/lib/v2/appledaily/radar.js b/lib/v2/appledaily/radar.js new file mode 100644 index 0000000000..139442d273 --- /dev/null +++ b/lib/v2/appledaily/radar.js @@ -0,0 +1,157 @@ +module.exports = { + 'appledaily.com': { + _name: '苹果新闻网', + tw: [ + { + title: '首頁', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/:channel'], + target: (params) => { + if (params.channel === 'home') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '焦点', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'recommend') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '最新', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'new') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '热门', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'hot') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '生活', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'life') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '娱乐', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'entertainment') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '社会', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'local') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '财经地产', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'property') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '国际', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'international') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '政治', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'politics') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '3C车城', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'gadget') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '吃喝玩乐', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'supplement') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '体育', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'sports') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '苹评理', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'forum') { + return '/appledaily/:channel'; + } + }, + }, + { + title: '微视频', + docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang', + source: ['/realtime/:channel'], + target: (params) => { + if (params.channel === 'micromovie') { + return '/appledaily/:channel'; + } + }, + }, + ], + }, +}; diff --git a/lib/v2/appledaily/router.js b/lib/v2/appledaily/router.js new file mode 100644 index 0000000000..91b8719d66 --- /dev/null +++ b/lib/v2/appledaily/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:channel?', require('./index')); +}; diff --git a/lib/v2/appledaily/templates/content.art b/lib/v2/appledaily/templates/content.art new file mode 100644 index 0000000000..886c0a8b3e --- /dev/null +++ b/lib/v2/appledaily/templates/content.art @@ -0,0 +1,7 @@ +{{ each content_elements }} + {{ if $value.type === 'image' }} + {{ $value.caption }} + {{ else if $value.type === 'text' }} +

{{ $value.content }}

+ {{ /if }} +{{ /each }}