From 65c2909640d936a52885cbcb1cdc652f83640c80 Mon Sep 17 00:00:00 2001 From: ueiu <39592269+ueiu@users.noreply.github.com> Date: Tue, 6 Jun 2023 22:07:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E4=B8=AD=E5=9B=BD=E6=94=BF?= =?UTF-8?q?=E5=BA=9C=E7=BD=91=E6=B2=A1=E6=9C=89=E6=AD=A3=E7=A1=AE=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5=E7=9B=B8=E5=AF=B9=E5=9C=B0=E5=9D=80=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=20&&=20=E6=9B=BF=E6=8D=A2=E6=BB=9A=E5=8A=A8=E6=96=B0=E9=97=BB?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=20(#12622)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update index.js * fix(route): 中国政府网没有正确拼接相对地址路径 && 替换滚动新闻地址 --- lib/v2/gov/news/index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/v2/gov/news/index.js b/lib/v2/gov/news/index.js index e8e5ef384..ddb38b1f5 100644 --- a/lib/v2/gov/news/index.js +++ b/lib/v2/gov/news/index.js @@ -4,24 +4,26 @@ const logger = require('@/utils/logger'); module.exports = async (ctx) => { const uid = ctx.params.uid; + const originDomain = 'https://www.gov.cn'; let url = ''; let title = ''; let list = ''; switch (uid) { case 'bm': - url = `http://www.gov.cn/lianbo/bumen/index.htm`; + url = `${originDomain}/lianbo/bumen/index.htm`; title = '中国政府网 - 部门政务'; break; case 'yw': - url = `http://www.gov.cn/yaowen/index.htm`; + url = `${originDomain}/yaowen/index.htm`; title = '中国政府网 - 新闻要闻'; break; case 'gd': - url = `http://www.gov.cn/xinwen/gundong.htm`; + // 因 /xinwen/gundong.htm 被重定向到 /yaowen/index.htm, 所以这里直接用要闻的代替了 + url = `${originDomain}/yaowen/index.htm`; title = '中国政府网 - 滚动新闻'; break; case 'gwy': - url = 'http://www.gov.cn/pushinfo/v150203/'; + url = `${originDomain}/pushinfo/v150203/`; title = '中国政府网 - 国务院信息'; break; case 'zhengce': @@ -75,9 +77,9 @@ module.exports = async (ctx) => { } else { href = item.find('a').attr('href'); if (href.startsWith('.')) { - href = href.slice(1); + href = new URL(href, url).pathname; } - contentUrl = href.startsWith('/') ? `http://www.gov.cn${href}` : href; + contentUrl = href.startsWith('/') ? `${originDomain}${href}` : href; if (!contentUrl.includes('content')) { description = item.find('a').text(); // 忽略获取吹风会的全文 } else {