From 9dc20280e823c37f53d2fcc49b90eab76b0f7645 Mon Sep 17 00:00:00 2001 From: heunghingwan Date: Mon, 14 Mar 2022 21:08:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20gov/fmprc/fyrbt=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=8F=91=E5=B8=83=E6=97=A5=E6=9C=9F=E6=8F=90=E5=8F=96?= =?UTF-8?q?=20(#9317)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复发布日期提取 * fix: depreciated url.resolve Invalid Date --- lib/routes/gov/fmprc/utils.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/routes/gov/fmprc/utils.js b/lib/routes/gov/fmprc/utils.js index 037e1c47b..1b587e712 100644 --- a/lib/routes/gov/fmprc/utils.js +++ b/lib/routes/gov/fmprc/utils.js @@ -1,19 +1,16 @@ const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); const cheerio = require('cheerio'); -const url = require('url'); // 加载文章页 async function load(link) { const response = await got.get(link); const $ = cheerio.load(response.data); - const date = new Date( - $('#News_Body_Time') - .text() - .match(/\d{4}-\d{2}-\d{2}/) - ); + const date = parseDate($('.time').text(), 'YYYY-MM-DD HH:mm'); - const pubDate = new Date(date.getTime()).toUTCString(); + const pubDate = timezone(date, +8); // 提取内容 const description = $('#News_Body_Txt_A').html(); @@ -30,13 +27,12 @@ const ProcessFeed = (list, caches) => { const $title = $('a'); // 还原相对链接为绝对链接 - const itemUrl = url.resolve(host, $title.attr('href')); + const itemUrl = new URL($title.attr('href'), host); // 列表上提取到的信息 const single = { title: $.text(), link: itemUrl, - guid: itemUrl, }; // 使用tryGet方法从缓存获取内容。 @@ -44,7 +40,7 @@ const ProcessFeed = (list, caches) => { const other = await caches.tryGet(itemUrl, () => load(itemUrl)); // 合并解析后的结果集作为该篇文章最终的输出结果 - return Promise.resolve(Object.assign({}, single, other)); + return { ...single, ...other }; }) ); };