fix(route): 国家药品监督管理局医疗器械标准管理中心 (#13919)
* fix(route): 国家药品监督管理局医疗器械标准管理中心 * fix: radar path matching ---------
This commit is contained in:
parent
a322dae132
commit
e6770d35af
|
|
@ -37,7 +37,7 @@ module.exports = {
|
|||
'/moj/aac/news/:type?': ['TonyRL'],
|
||||
'/mot/:category?': ['nczitzk'],
|
||||
'/news/:uid': ['EsuRt'],
|
||||
'/nifdc/:path+': ['nczitzk'],
|
||||
'/nifdc/:path?': ['nczitzk'],
|
||||
'/nmpa/:path+': ['TonyRL'],
|
||||
'/nopss/:path+': ['nczitzk'],
|
||||
'/npc/:caty': ['233yeee'],
|
||||
|
|
|
|||
|
|
@ -4,58 +4,55 @@ const timezone = require('@/utils/timezone');
|
|||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const params = ctx.path === '/nifdc' ? '/nifdc/bshff/ylqxbzhgl/qxggtzh' : ctx.path;
|
||||
const { path = 'bshff/ylqxbzhgl/qxggtzh' } = ctx.params;
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
|
||||
|
||||
const rootUrl = 'https://www.nifdc.org.cn';
|
||||
const currentUrl = `${rootUrl}${params}/index.html`;
|
||||
const currentUrl = new URL(`nifdc/${path}/`, rootUrl).href;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const { data: response } = await got(currentUrl);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
let items = $('.list ul li a')
|
||||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20)
|
||||
let items = $('div.list ul li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const link = item.attr('href');
|
||||
const a = item.find('a');
|
||||
const link = a.prop('href');
|
||||
|
||||
return {
|
||||
title: item.text(),
|
||||
link: /^http/.test(link) ? link : new URL(link, currentUrl).href,
|
||||
pubDate: parseDate(
|
||||
item
|
||||
.next()
|
||||
.text()
|
||||
.match(/\((.*)\)/)
|
||||
),
|
||||
title: a.prop('title') || a.text(),
|
||||
link: link.startsWith('http') ? link : new URL(link, currentUrl).href,
|
||||
pubDate: parseDate(item.find('span').text().replace(/\(|\)/g, '')),
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
if (/^https:\/\/www\.nmpa\.gov\.cn\//.test(item.link)) {
|
||||
const { data: html } = await got(item.link);
|
||||
try {
|
||||
const { data: detailResponse } = await got(item.link);
|
||||
|
||||
const content = cheerio.load(html);
|
||||
const content = cheerio.load(detailResponse);
|
||||
|
||||
item.description = content('.text').html();
|
||||
item.pubDate = timezone(parseDate($('meta[name="PubDate"]').attr('content')), +8);
|
||||
} else {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
item.title = content('.title').text();
|
||||
item.description = content('div.text').append(content('div.fujian')).html();
|
||||
item.author = content('meta[name="ContentSource"]').prop('content');
|
||||
item.category = [
|
||||
...new Set([content('meta[name="ColumnName"]').prop('content'), content('meta[name="ColumnType"]').prop('content'), ...(content('meta[name="ColumnKeywords"]').prop('content').split(/,|;/) ?? [])]),
|
||||
].filter((c) => c);
|
||||
item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').prop('content')), +8);
|
||||
item.enclosure_url = content('a.fujianClass').first().prop('href');
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.text').append(content('.fujian')).html();
|
||||
item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').attr('content')), +8);
|
||||
if (item.enclosure_url) {
|
||||
item.enclosure_url = new URL(item.enclosure_url, rootUrl).href;
|
||||
item.enclosure_type = `application/${item.enclosure_url.split(/\./).pop()}`;
|
||||
}
|
||||
} catch (e) {
|
||||
// no-empty
|
||||
}
|
||||
|
||||
return item;
|
||||
|
|
@ -63,9 +60,19 @@ module.exports = async (ctx) => {
|
|||
)
|
||||
);
|
||||
|
||||
const image = new URL($('div.logo img').prop('src'), currentUrl).href;
|
||||
const icon = new URL($('link[rel="shortcut icon"]').prop('href'), currentUrl).href;
|
||||
|
||||
ctx.state.data = {
|
||||
item: items,
|
||||
title: $('title').text().replace(/----/, ' - '),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
description: $('meta[name="ColumnDescription"]').prop('content'),
|
||||
language: 'zh',
|
||||
image,
|
||||
icon,
|
||||
logo: icon,
|
||||
subtitle: $('meta[ name="ColumnName"]').prop('content'),
|
||||
author: $('meta[name="SiteName"]').prop('content'),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1054,8 +1054,8 @@ module.exports = {
|
|||
{
|
||||
title: '通用',
|
||||
docs: 'https://docs.rsshub.app/routes/government#guo-jia-yao-pin-jian-du-guan-li-ju-yi-liao-qi-xie-biao-zhun-guan-li-zhong-xin',
|
||||
source: ['/*path'],
|
||||
target: (params) => `/gov/nifdc/${params.path.replace('/index.html', '')}`,
|
||||
source: ['/*'],
|
||||
target: (params) => `/gov/nifdc/${params.path.replace(/\/index\.html$/, '')}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ module.exports = function (router) {
|
|||
router.get('/mofcom/article/:suffix+', require('./mofcom/article'));
|
||||
router.get('/moj/aac/news/:type?', require('./moj/aac/news'));
|
||||
router.get('/news/:uid', require('./news'));
|
||||
router.get(/nifdc\/([\w/-]+)?/, require('./nifdc'));
|
||||
router.get('/nifdc/:path*', require('./nifdc'));
|
||||
router.get(/\/nmpa\/([\w][\w/]+)?/, require('./nmpa/generic'));
|
||||
router.get(/nopss(\/[\w/-]+)?/, require('./nopss'));
|
||||
router.get('/npc/:caty', require('./npc/index'));
|
||||
|
|
|
|||
|
|
@ -669,7 +669,7 @@ Language
|
|||
|
||||
### 通用 {#guo-jia-yao-pin-jian-du-guan-li-ju-yi-liao-qi-xie-biao-zhun-guan-li-zhong-xin-tong-yong}
|
||||
|
||||
<Route author="nczitzk" example="/gov/nifdc/bshff/ylqxbzhgl/qxggtzh" path="/gov/nifdc/:path+" paramsDesc={['路径,默认为公告通告']} radar="1" rssbud="1">
|
||||
<Route author="nczitzk" example="/gov/nifdc/bshff/ylqxbzhgl/qxggtzh" path="/gov/nifdc/:path?" paramsDesc={['路径,默认为公告通告']} radar="1" rssbud="1">
|
||||
|
||||
:::tip
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue