From 64e0efebc25c08b5822d69c611df6a91aaf5d565 Mon Sep 17 00:00:00 2001 From: oppilate <64395752+oppilate@users.noreply.github.com> Date: Tue, 24 Nov 2020 12:03:18 +0000 Subject: [PATCH] feat: add wsj cn (#6207) --- docs/en/traditional-media.md | 2 +- docs/traditional-media.md | 20 ++++++++++---------- lib/router.js | 2 +- lib/routes/wsj/index.js | 22 ++++++++++++++++------ 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index f96b5d2bf..74a7489a6 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -227,7 +227,7 @@ Provides a better reading experience (full text articles) over the official one. ### News - + Provide full article RSS for WSJ topics. diff --git a/docs/traditional-media.md b/docs/traditional-media.md index c4da55581..40d6ab296 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -197,16 +197,6 @@ Solidot 提供的 feed: -## The Wall Street Journal (WSJ) - -### 新闻 - - - -通过提取文章全文,以提供比官方源更佳的阅读体验。 - - - ## UDN ### 轉角國際 @@ -378,6 +368,16 @@ Type 栏目: +## 华尔街日报 The Wall Street Journal (WSJ) + +### 新闻 + + + +通过提取文章全文,以提供比官方源更佳的阅读体验。 + + + ## 极客公园 ### 全球快讯 diff --git a/lib/router.js b/lib/router.js index 7fdfaca79..b3505419d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3463,7 +3463,7 @@ router.get('/liquipedia/dota2/matches/:id', require('./routes/liquipedia/dota2_m router.get('/gov/harbin/kjj', require('./routes/gov/harbin/kjj')); // WSJ -router.get('/wsj/:lang/:category', require('./routes/wsj/index')); +router.get('/wsj/:lang/:category?', require('./routes/wsj/index')); // China File router.get('/chinafile/:category?', require('./routes/chinafile/index')); diff --git a/lib/routes/wsj/index.js b/lib/routes/wsj/index.js index 601e70e90..0f82f6ec5 100644 --- a/lib/routes/wsj/index.js +++ b/lib/routes/wsj/index.js @@ -24,12 +24,22 @@ module.exports = async (ctx) => { const language = ctx.params.lang; const category = ctx.params.category; let rssUrl; - if (language === 'en-us') { - rssUrl = `https://feeds.a.dj.com/rss/${categoryToXMLFileName[category]}`; - } else { - // Doesn't support other languages (e.g. zh-cn, zh-tw, ja) for now - return; + switch (language) { + case 'en-us': + rssUrl = `https://feeds.a.dj.com/rss/${categoryToXMLFileName[category]}`; + break; + case 'zh-cn': + // Doesn't support categorical subscribtion + rssUrl = `https://cn.wsj.com/zh-hans/rss/`; + break; + case 'zh-tw': + rssUrl = `https://cn.wsj.com/zh-hant/rss/`; + break; + default: + // Doesn't support other languages (e.g. ja) for now + throw Error(`Language ${language} is not supported`); } + const feed = await parser.parseURL(rssUrl); const chromeMobileUserAgent = 'Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/67.0.3396.87 Mobile Safari/537.36'; @@ -38,7 +48,7 @@ module.exports = async (ctx) => { async (item) => await ctx.cache.tryGet(item.link, async () => { // Fetch the AMP version - const url = item.link.replace(/^https:\/\/www\.wsj\.com/, 'https://www.wsj.com/amp'); + const url = item.link.replace(/(?<=^https:\/\/\w+\.wsj\.com)/, '/amp'); const response = await got({ url, method: 'get',