mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-31 01:01:11 +08:00
fix(route): broken link embassy/us (#9673)
* Fix broken link embassy/us * refactor: migrate to v2 * fix: embassy/us selector
This commit is contained in:
+2
-2
@@ -836,8 +836,8 @@ router.get('/iplay/home', lazyloadRouteHandler('./routes/iplay/home'));
|
||||
// xclient.info
|
||||
router.get('/xclient/app/:name', lazyloadRouteHandler('./routes/xclient/app'));
|
||||
|
||||
// 中国驻外使领事馆
|
||||
router.get('/embassy/:country/:city?', lazyloadRouteHandler('./routes/embassy/index'));
|
||||
// 中国驻外使领事馆 migrated to v2
|
||||
// router.get('/embassy/:country/:city?', lazyloadRouteHandler('./routes/embassy/index'));
|
||||
|
||||
// 澎湃新闻
|
||||
// router.get('/thepaper/featured', lazyloadRouteHandler('./routes/thepaper/featured'));
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
const got = require('@/utils/got');
|
||||
const url = require('url');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const supportedList = require('./supportedList');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const country = ctx.params.country;
|
||||
const city = ctx.params.city || undefined;
|
||||
|
||||
let config = supportedList[country.toLowerCase()];
|
||||
let desc;
|
||||
|
||||
if (city === undefined) {
|
||||
desc = `中国驻${config.countryCN}大使馆 -- 重要通知`;
|
||||
} else {
|
||||
config = config.consulates[city.toLowerCase()];
|
||||
desc = `中国驻${config.cityCN}领事馆 -- 重要通知`;
|
||||
}
|
||||
|
||||
const link = config.link;
|
||||
const hostname = url.parse(link).hostname;
|
||||
|
||||
const res = await got.get(link);
|
||||
const $ = cheerio.load(res.data);
|
||||
|
||||
const list = [];
|
||||
|
||||
$(config.list)
|
||||
.slice(0, 10)
|
||||
.each((i, e) => {
|
||||
const temp = url.resolve(link, $(e).attr('href'));
|
||||
if (url.parse(temp).hostname === hostname) {
|
||||
list.push(temp);
|
||||
}
|
||||
});
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (link) => {
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await got.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
const single = {
|
||||
title: $(config.title).text(),
|
||||
link,
|
||||
description: $(config.description).html(),
|
||||
pubDate: new Date($(config.pubDate).text().replace('(', '').replace(')', '')).toUTCString(),
|
||||
};
|
||||
ctx.cache.set(link, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: desc,
|
||||
description: desc,
|
||||
link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const supportedList = require('./supportedList');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const country = ctx.params.country;
|
||||
const city = ctx.params.city ?? undefined;
|
||||
|
||||
let config = supportedList[country.toLowerCase()];
|
||||
let desc;
|
||||
|
||||
if (city === undefined) {
|
||||
desc = `中国驻${config.countryCN}大使馆 -- 重要通知`;
|
||||
} else {
|
||||
config = config.consulates[city.toLowerCase()];
|
||||
desc = `中国驻${config.cityCN}领事馆 -- 重要通知`;
|
||||
}
|
||||
|
||||
const link = config.link;
|
||||
const hostname = new URL(link).hostname;
|
||||
|
||||
const res = await got(link);
|
||||
const $ = cheerio.load(res.data);
|
||||
|
||||
const list = [];
|
||||
|
||||
$(config.list)
|
||||
.slice(0, 10)
|
||||
.each((i, e) => {
|
||||
const temp = new URL($(e).attr('href'), link);
|
||||
if (temp.hostname === hostname) {
|
||||
list.push(temp);
|
||||
}
|
||||
});
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map((link) =>
|
||||
ctx.cache.tryGet(link.href, async () => {
|
||||
const response = await got(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
const single = {
|
||||
title: $(config.title).text(),
|
||||
link,
|
||||
description: $(config.description).html(),
|
||||
pubDate: parseDate($(config.pubDate).text().replace('(', '').replace(')', '')),
|
||||
};
|
||||
return single;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: desc,
|
||||
description: desc,
|
||||
link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/:country/:city?': ['HenryQW'],
|
||||
};
|
||||
@@ -0,0 +1,258 @@
|
||||
module.exports = {
|
||||
'china-embassy.org': {
|
||||
_name: '中国驻外使领馆',
|
||||
ca: [
|
||||
{
|
||||
title: '重要通知 - 加拿大大使馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/zytz', '/'],
|
||||
target: '/embassy/ca',
|
||||
},
|
||||
],
|
||||
jp: [
|
||||
{
|
||||
title: '通知通告 - 日本大使馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/lsfws/LSB', '/'],
|
||||
target: '/embassy/jp',
|
||||
},
|
||||
],
|
||||
kr: [
|
||||
{
|
||||
title: '重要通知 - 韩国大使馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/lsqz/ls_tz', '/'],
|
||||
target: '/embassy/kr',
|
||||
},
|
||||
],
|
||||
my: [
|
||||
{
|
||||
title: '重要通知 - 马来西亚大使馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/zytz', '/'],
|
||||
target: '/embassy/my',
|
||||
},
|
||||
],
|
||||
sg: [
|
||||
{
|
||||
title: '重要通知 - 新加坡大使馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/lsfw/zytzs', '/'],
|
||||
target: '/embassy/sg',
|
||||
},
|
||||
],
|
||||
},
|
||||
'china-embassy.gov.cn': {
|
||||
_name: '中国驻外使领馆',
|
||||
us: [
|
||||
{
|
||||
title: '重要通知 - 美国大使馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/zytz', '/'],
|
||||
target: '/embassy/us',
|
||||
},
|
||||
],
|
||||
},
|
||||
'chinese-embassy.org.uk': {
|
||||
_name: '中国驻外使领馆',
|
||||
www: [
|
||||
{
|
||||
title: '领事协助 - 英国大使馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/lsfw/lsxz', '/'],
|
||||
target: '/embassy/us',
|
||||
},
|
||||
],
|
||||
},
|
||||
'chineseembassy.org': {
|
||||
_name: '中国驻外使领馆',
|
||||
de: [
|
||||
{
|
||||
title: '近期通知 - 德国大使馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/lsfw/jqtz', '/'],
|
||||
target: '/embassy/de',
|
||||
},
|
||||
],
|
||||
fr: [
|
||||
{
|
||||
title: '重要通知 - 法国大使馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/zgzfg/zgsg/lsb', '/'],
|
||||
target: '/embassy/fr',
|
||||
},
|
||||
],
|
||||
},
|
||||
'china-consulate.org': {
|
||||
_name: '中国驻外使领馆',
|
||||
marseille: [
|
||||
{
|
||||
title: '领事服务最新公告 - 马赛总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/lsfwgg', '/'],
|
||||
target: '/embassy/fr/marseille',
|
||||
},
|
||||
],
|
||||
strasbourg: [
|
||||
{
|
||||
title: '重要通知 - 斯特拉斯堡总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/lsfw', '/'],
|
||||
target: '/embassy/fr/strasbourg',
|
||||
},
|
||||
],
|
||||
lyon: [
|
||||
{
|
||||
title: '通知、通告 - 里昂总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/tztg', '/'],
|
||||
target: '/embassy/fr/lyon',
|
||||
},
|
||||
],
|
||||
nagasaki: [
|
||||
{
|
||||
title: '通知公告 - 长崎总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/tzgg', '/'],
|
||||
target: '/embassy/jp/nagasaki',
|
||||
},
|
||||
],
|
||||
osaka: [
|
||||
{
|
||||
title: '通知公告 - 大阪总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/tzgg', '/'],
|
||||
target: '/embassy/jp/osaka',
|
||||
},
|
||||
],
|
||||
fukuoka: [
|
||||
{
|
||||
title: '通知公告 - 福冈总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/tzgg', '/'],
|
||||
target: '/embassy/jp/fukuoka',
|
||||
},
|
||||
],
|
||||
sapporo: [
|
||||
{
|
||||
title: '通知公告 - 札幌总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/tzgg', '/'],
|
||||
target: '/embassy/jp/sapporo',
|
||||
},
|
||||
],
|
||||
niigata: [
|
||||
{
|
||||
title: '通知通告 - 新潟总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/lsbh/tztg', '/'],
|
||||
target: '/embassy/jp/niigata',
|
||||
},
|
||||
],
|
||||
busan: [
|
||||
{
|
||||
title: '通知公告 - 釜山总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/lsfw/tzgg101', '/'],
|
||||
target: '/embassy/kr/busan',
|
||||
},
|
||||
],
|
||||
gwangju: [
|
||||
{
|
||||
title: '公告通知 - 光州总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/lbxx/ggtz', '/'],
|
||||
target: '/embassy/kr/gwangju',
|
||||
},
|
||||
],
|
||||
edinburgh: [
|
||||
{
|
||||
title: '重要通知 - 爱丁堡总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/zytz', '/'],
|
||||
target: '/embassy/uk/edinburgh',
|
||||
},
|
||||
],
|
||||
newyork: [
|
||||
{
|
||||
title: '重要通知 - 纽约总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/fwzc/zxtz', '/'],
|
||||
target: '/embassy/us/newyork',
|
||||
},
|
||||
],
|
||||
},
|
||||
'chinaconsulatechicago.org': {
|
||||
_name: '中国驻外使领馆',
|
||||
www: [
|
||||
{
|
||||
title: '领馆重要通知 - 芝加哥总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/zytz', '/'],
|
||||
target: '/embassy/us/chicago',
|
||||
},
|
||||
],
|
||||
},
|
||||
'chinaconsulatesf.org': {
|
||||
_name: '中国驻外使领馆',
|
||||
www: [
|
||||
{
|
||||
title: '重要通知 - 旧金山总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/zytz', '/'],
|
||||
target: '/embassy/us/sanfrancisco',
|
||||
},
|
||||
],
|
||||
},
|
||||
'chineseconsulate.org': {
|
||||
_name: '中国驻外使领馆',
|
||||
montreal: [
|
||||
{
|
||||
title: '重要通知 - 蒙特利尔总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/zytz', '/'],
|
||||
target: '/embassy/ca/montreal',
|
||||
},
|
||||
],
|
||||
munich: [
|
||||
{
|
||||
title: '近期通知 - 慕尼黑总领馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/jqtz', '/'],
|
||||
target: '/embassy/de/munich',
|
||||
},
|
||||
],
|
||||
nagoya: [
|
||||
{
|
||||
title: '通知公告 - 名古屋总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: '',
|
||||
target: '/embassy/jp/nagoya',
|
||||
},
|
||||
],
|
||||
jeju: [
|
||||
{
|
||||
title: '公告栏 - 济州总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/ggl', '/'],
|
||||
target: '/embassy/kr/jeju',
|
||||
},
|
||||
],
|
||||
belfast: [
|
||||
{
|
||||
title: '通知通告 - 贝尔法斯特总领馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/tztg', '/'],
|
||||
target: '/embassy/uk/belfast',
|
||||
},
|
||||
],
|
||||
manchester: [
|
||||
{
|
||||
title: '通知公告 - 曼彻斯特总领事馆',
|
||||
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan',
|
||||
source: ['/chn/tzgg', '/'],
|
||||
target: '/embassy/uk/manchester',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/:country/:city?', require('./index'));
|
||||
};
|
||||
@@ -222,11 +222,11 @@ module.exports = {
|
||||
us: {
|
||||
country: 'us',
|
||||
countryCN: '美国',
|
||||
link: 'http://www.china-embassy.org/chn/lszj/zytz/',
|
||||
list: 'div#docMore a',
|
||||
title: '#News_Body_Title',
|
||||
description: '#News_Body_Txt_A',
|
||||
pubDate: '#News_Body_Time > div:nth-child(1) > span',
|
||||
link: 'http://us.china-embassy.gov.cn/zytz/',
|
||||
list: '.list-content ul li a',
|
||||
title: 'div.title',
|
||||
description: 'div.trs_editor_view',
|
||||
pubDate: 'div.date',
|
||||
consulates: {
|
||||
chicago: {
|
||||
cityCN: '芝加哥',
|
||||
Reference in New Issue
Block a user