From 9e1796944fc9f997d2ba422dd10765dd3c69916e Mon Sep 17 00:00:00 2001 From: miles Date: Wed, 31 Aug 2022 16:16:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=81=AF=E5=90=88?= =?UTF-8?q?=E6=96=B0=E8=81=9E=E7=B6=B2=20(#10654)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 聯合新聞網 * fix(route): concatenate the url correctly * feat(route): fetch link name * feat(route): description uses HTML instead of raw text * feat(route): remove `from` search params from link * feat(route): improve feed description readability * fix(route): article was not properly parsed * refactor(route): improve feed fetching --- docs/traditional-media.md | 12 +++++ lib/v2/udn/breaking-news.js | 85 +++++++++++++++++++++++++++++++++ lib/v2/udn/maintainer.js | 3 ++ lib/v2/udn/radar.js | 13 +++++ lib/v2/udn/router.js | 3 ++ lib/v2/udn/templates/figure.art | 4 ++ 6 files changed, 120 insertions(+) create mode 100644 lib/v2/udn/breaking-news.js create mode 100644 lib/v2/udn/maintainer.js create mode 100644 lib/v2/udn/radar.js create mode 100644 lib/v2/udn/router.js create mode 100644 lib/v2/udn/templates/figure.art diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 10e929b8a7..5dbcb95bf1 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1376,6 +1376,18 @@ category 对应的关键词有 +## 聯合新聞網 + +### 即時新聞 + + + +| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 99 | +| -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | --- | +| 精選 | 要聞 | 社會 | 地方 | 兩岸 | 國際 | 財經 | 運動 | 娛樂 | 生活 | 股市 | 文教 | 數位 | 不分類 | + + + ## 路透社 ::: warning 迁移说明 diff --git a/lib/v2/udn/breaking-news.js b/lib/v2/udn/breaking-news.js new file mode 100644 index 0000000000..9f3ee3c94c --- /dev/null +++ b/lib/v2/udn/breaking-news.js @@ -0,0 +1,85 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const cheerio = require('cheerio'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const link = `/news/breaknews/1/${id}#breaknews`; + const name = await getLinkName(ctx, link); + const rootUrl = 'https://udn.com'; + const response = await got(`${rootUrl}/api/more?page=1&channelId=1&cate_id=${id}&type=breaknews`); + const items = await Promise.all( + response.data.lists.map((item) => { + let link = item.titleLink.indexOf('http://') === 0 || item.titleLink.indexOf('https://') === 0 ? item.titleLink : `${rootUrl}${item.titleLink}`; + const linkUrl = new URL(link); + // cleanup query paramter + linkUrl.query = linkUrl.search = ''; + link = linkUrl.toString(); + return ctx.cache.tryGet(link, async () => { + let result = await got(link); + // VIP article requires redirection + // e.g. https://udn.com/news/story/7331/6576320 + const vip = result.data.match(/