From 47bbbedf7ac233f32f961a470dfd36fd22bcbb00 Mon Sep 17 00:00:00 2001 From: oppilate <64395752+oppilate@users.noreply.github.com> Date: Tue, 22 Feb 2022 15:08:04 +0000 Subject: [PATCH] fix(route): wsj (#7795) * Fix wsj missing contents * Update lib/routes/wsj/index.js * Update lib/routes/wsj/index.js * fix merging errors * update matching rules * refactor: migrate to v2 Duplicated issue: Close #8298 Co-authored-by: oppilate Co-authored-by: NeverBehave Co-authored-by: TonyRL --- lib/router.js | 4 ++-- lib/{routes => v2}/wsj/index.js | 10 ++++++---- lib/v2/wsj/maintainer.js | 3 +++ lib/v2/wsj/radar.js | 21 +++++++++++++++++++++ lib/v2/wsj/router.js | 3 +++ 5 files changed, 35 insertions(+), 6 deletions(-) rename lib/{routes => v2}/wsj/index.js (94%) create mode 100644 lib/v2/wsj/maintainer.js create mode 100644 lib/v2/wsj/radar.js create mode 100644 lib/v2/wsj/router.js diff --git a/lib/router.js b/lib/router.js index f2366932e..addbec5e2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3445,8 +3445,8 @@ router.get('/liquipedia/dota2/matches/:id', lazyloadRouteHandler('./routes/liqui // 哈尔滨市科技局 router.get('/gov/harbin/kjj', lazyloadRouteHandler('./routes/gov/harbin/kjj')); -// WSJ -router.get('/wsj/:lang/:category?', lazyloadRouteHandler('./routes/wsj/index')); +// WSJ migrated to v2 +// router.get('/wsj/:lang/:category?', lazyloadRouteHandler('./routes/wsj/index')); // China File router.get('/chinafile/:category?', lazyloadRouteHandler('./routes/chinafile/index')); diff --git a/lib/routes/wsj/index.js b/lib/v2/wsj/index.js similarity index 94% rename from lib/routes/wsj/index.js rename to lib/v2/wsj/index.js index 131a6efce..4c7b82c0c 100644 --- a/lib/routes/wsj/index.js +++ b/lib/v2/wsj/index.js @@ -1,6 +1,7 @@ const parser = require('@/utils/rss-parser'); const cheerio = require('cheerio'); const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); const categoryToXMLFileName = { opinion: 'RSSOpinion.xml', @@ -57,7 +58,7 @@ module.exports = async (ctx) => { }); const html = response.body; const $ = cheerio.load(html); - const content = $('.articleBody > div[amp-access="access"]'); + const content = $('.articleBody > section'); // Cover const cover = $('.articleLead > div.is-lead-inset > div.header > .img-header > div.image-container > amp-img > img'); @@ -73,6 +74,7 @@ module.exports = async (ctx) => { // Metadata (categories & updatedAt) const updatedAt = $('meta[itemprop="dateModified"]').attr('content'); const publishedAt = $('meta[itemprop="datePublished"]').attr('content'); + const author = $('.author > a[rel="author"]').html(); const categories = $('meta[name="keywords"]') .attr('content') @@ -113,9 +115,9 @@ module.exports = async (ctx) => { return { title: item.title, id: item.guid, - pubDate: new Date(publishedAt).toUTCString(), - updated: new Date(updatedAt).toUTCString(), - author: item.creator, + pubDate: parseDate(publishedAt), + updated: parseDate(updatedAt), + author, link: item.link, summary, description: content.html(), diff --git a/lib/v2/wsj/maintainer.js b/lib/v2/wsj/maintainer.js new file mode 100644 index 000000000..eac2ec0b8 --- /dev/null +++ b/lib/v2/wsj/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:lang/:category?': ['oppilate'], +}; diff --git a/lib/v2/wsj/radar.js b/lib/v2/wsj/radar.js new file mode 100644 index 000000000..1b59052da --- /dev/null +++ b/lib/v2/wsj/radar.js @@ -0,0 +1,21 @@ +module.exports = { + 'wsj.com': { + _name: '华尔街日报 The Wall Street Journal (WSJ)', + cn: [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/traditional-media.html#hua-er-jie-ri-bao-the-wall-street-journal-wsj', + souce: '/', + target: '/wsj/zh-cn', + }, + ], + www: [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/traditional-media.html#hua-er-jie-ri-bao-the-wall-street-journal-wsj', + souce: '/', + target: '/wsj/en-us', + }, + ], + }, +}; diff --git a/lib/v2/wsj/router.js b/lib/v2/wsj/router.js new file mode 100644 index 000000000..accf74aab --- /dev/null +++ b/lib/v2/wsj/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:lang/:category?', require('./index')); +};