From 7fdffa91332b16f0b85fc4ef0f0c1095a07bd92b Mon Sep 17 00:00:00 2001 From: Felix Hsu Date: Sat, 24 Sep 2022 00:21:47 +0800 Subject: [PATCH] refactor: Stats gov, change the img href from relative href to absolute href for better rss reading experiences. (#10875) * add new statsgov * Fix radar.js * 1. Fix the missing optional chaining operator in reg matching 2. add the missing timezone change * remove the dup $ in item * optimize url * stats.gov.cn refactored * Modify doc * more flexible pathname parsing * Fix radar data * change image src to absolute src * more accurate comment. --- lib/v2/gov/stats/utils.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/v2/gov/stats/utils.js b/lib/v2/gov/stats/utils.js index a838d0f05..ce2a459d4 100644 --- a/lib/v2/gov/stats/utils.js +++ b/lib/v2/gov/stats/utils.js @@ -33,6 +33,15 @@ const parseXilan = async (item, ctx) => const title = $('.xilan_titf').text(); item.author = title.match(/来源:(.*)发布时间/)?.[1].trim() ?? '国家统计局'; item.pubDate = timezone(parseDate(title.match(/发布时间:(.*)/)?.[1].trim() ?? item.pubDate), +8); + + // Change the img src from relative to absolute for a better compatibility + $('.xilan_con') + .find('img') + .each((_, el) => { + $(el).attr('src', new URL($(el).attr('src'), item.link).href); + // oldsrc is causing freshrss imageproxy not to work correctly + $(el).removeAttr('oldsrc').removeAttr('alt'); + }); item.description = $('.xilan_con').html(); const attachmentTitle = $('.wenzhang_tit').filter(function () {