diff --git a/docs/new-media.md b/docs/new-media.md index 6573bf504..70ac74581 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -306,6 +306,22 @@ pageClass: routes +## Focus Taiwan + +### Category + + + +| Latest | Editor's Picks | Photos of the Day | +| ------ | -------------- | ----------------- | +| news | editorspicks | photos | + +| Politics | Cross-strait | Business | Society | Science & Tech | Culture | Sports | +| -------- | ------------ | -------- | ------- | -------------- | ------- | ------ | +| politics | cross-strait | business | society | science & tech | culture | sports | + + + ## GQ ### GQ 台湾 diff --git a/lib/v2/focustaiwan/index.js b/lib/v2/focustaiwan/index.js new file mode 100644 index 000000000..18f4f704c --- /dev/null +++ b/lib/v2/focustaiwan/index.js @@ -0,0 +1,72 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const path = require('path'); +const { art } = require('@/utils/render'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'news'; + + const rootUrl = 'https://focustaiwan.tw'; + const currentUrl = `${rootUrl}/cna2019api/cna/FTNewsList`; + + const response = await got({ + method: 'post', + url: currentUrl, + form: { + action: 4, + category, + pageidx: 2, + pagesize: 50, + }, + }); + + const list = response.data.ResultData.Items.map((item) => ({ + title: item.HeadLine, + link: item.PageUrl, + category: item.ClassName, + pubDate: timezone(parseDate(item.CreateTime), +8), + })); + + 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('img').each(function () { + content(this).html(``); + }); + + const image = content('meta[property="og:image"]').attr('content'); + const matches = detailResponse.data.match(/var pAudio_url = "(.*)\.mp3";/); + + if (matches) { + item.enclosure_url = matches[1]; + item.enclosure_type = 'audio/mpeg'; + item.itunes_item_image = image; + } + + item.description = art(path.join(__dirname, 'templates/article.art'), { + image, + description: content('.paragraph').html(), + }); + + return item; + }) + ) + ); + + ctx.state.data = { + title: response.data.ResultData.MetaData.Title, + link: response.data.ResultData.MetaData.CanonicalUrl, + item: items, + itunes_author: 'Focus Taiwan', + image: 'https://imgcdn.cna.com.tw/Eng/website/img/default.png', + }; +}; diff --git a/lib/v2/focustaiwan/maintainer.js b/lib/v2/focustaiwan/maintainer.js new file mode 100644 index 000000000..81eb78d73 --- /dev/null +++ b/lib/v2/focustaiwan/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/focustaiwan/radar.js b/lib/v2/focustaiwan/radar.js new file mode 100644 index 000000000..6b70c73b2 --- /dev/null +++ b/lib/v2/focustaiwan/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'focustaiwan.tw': { + _name: 'Focus Taiwan', + '.': [ + { + title: 'Category', + docs: 'https://docs.rsshub.app/new-media.html#focus-taiwan-category', + source: ['/:category', '/'], + target: '/focustaiwan/category?', + }, + ], + }, +}; diff --git a/lib/v2/focustaiwan/router.js b/lib/v2/focustaiwan/router.js new file mode 100644 index 000000000..cf781366f --- /dev/null +++ b/lib/v2/focustaiwan/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?', require('./index')); +}; diff --git a/lib/v2/focustaiwan/templates/article.art b/lib/v2/focustaiwan/templates/article.art new file mode 100644 index 000000000..aca3499e9 --- /dev/null +++ b/lib/v2/focustaiwan/templates/article.art @@ -0,0 +1 @@ +
{{@ description }}