fix(route): gov/fmprc/fyrbt 修复发布日期提取 (#9317)
* 修复发布日期提取 * fix: depreciated url.resolve Invalid Date
This commit is contained in:
@@ -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 };
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user