From c9d84506889d64eae74cc158bb45fe86a0d35e53 Mon Sep 17 00:00:00 2001 From: Rongrong <15956627+Rongronggg9@users.noreply.github.com> Date: Wed, 2 Feb 2022 20:36:13 +0800 Subject: [PATCH] fix(route)(wechat/feeddd) (#8918) Signed-off-by: Rongrong <15956627+Rongronggg9@users.noreply.github.com> --- docs/new-media.md | 2 +- lib/v2/wechat/feeddd.js | 18 +++++++++++++----- lib/v2/wechat/maintainer.js | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/new-media.md b/docs/new-media.md index 4b33c8024..aa9188b5b 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -3105,7 +3105,7 @@ column 为 third 时可选的 category: ### 公众号 (feeddd 来源) - + ### 公众号栏目 (非推送 & 历史消息) diff --git a/lib/v2/wechat/feeddd.js b/lib/v2/wechat/feeddd.js index 81b9107ec..835963dda 100644 --- a/lib/v2/wechat/feeddd.js +++ b/lib/v2/wechat/feeddd.js @@ -12,15 +12,10 @@ module.exports = async (ctx) => { const response = await got(apiUrl); - if (response.data.items.length === 0) { - throw Error('Empty feed'); - } - let items = response.data.items.map((item) => ({ title: item.title, pubDate: parseDate(item.date_modified), link: item.url, - author: item.title, guid: item.id, })); @@ -51,6 +46,18 @@ module.exports = async (ctx) => { desc: $('#js_content').html(), }); + item.author = $('meta[name=author]').attr('content'); + + // another way to get publish timestamp: + // const publish_time_script = $('script[nonce][type="text/javascript"]:contains("var ct")').html(); + // const publish_time_match = publish_time_script && publish_time_script.match(/var ct *= *"(\d{10})"/); + const publish_time_script = $('script[nonce][type="text/javascript"]:contains("publish_time")').html(); + const publish_time_match = publish_time_script && publish_time_script.match(/var.*[ ,]n *= *"(\d{10})"/); + const publish_timestamp = publish_time_match && publish_time_match[1]; + if (publish_timestamp) { + item.pubDate = parseDate(publish_timestamp * 1000); + } + return item; }) ) @@ -61,6 +68,7 @@ module.exports = async (ctx) => { link: response.data.feed_url, description: response.data.title, item: items, + allowEmpty: true, }; ctx.state.json = { diff --git a/lib/v2/wechat/maintainer.js b/lib/v2/wechat/maintainer.js index 0f5e21d7c..0540a9dfc 100644 --- a/lib/v2/wechat/maintainer.js +++ b/lib/v2/wechat/maintainer.js @@ -1,3 +1,3 @@ module.exports = { - '/feeddd/:id': ['TonyRL'], + '/feeddd/:id': ['TonyRL', 'Rongronggg9'], };