fix(route): CDRHNew titleOnly (#10417)

* Update router.js

* Update radar.js

* Update cdrh.js

* Update cdrh.js

* Update cdrh.js

* Update cdrh.js

* Update cdrh.js

* docs: update paramsDesc
This commit is contained in:
terrytw 2022-08-08 22:48:00 +08:00 committed by GitHub
parent 226a3b1291
commit 7aa76219f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 5 deletions

View File

@ -400,7 +400,7 @@ pageClass: routes
### CDRHNew
<Route author="nczitzk" example="/fda/cdrh" path="/fda/cdrh" />
<Route author="nczitzk" example="/fda/cdrh" path="/fda/cdrh/:titleOnly?" :paramsDesc="['只显示标题,默认为空,即包含全文,其他任意值则只显示标题']"/>
## 美国中央情报局

View File

@ -3,6 +3,7 @@ const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const titleOnly = !!(ctx.params.titleOnly ?? '');
const rootUrl = 'https://www.fda.gov';
const currentUrl = `${rootUrl}/medical-devices/news-events-medical-devices/cdrhnew-news-and-updates`;
@ -29,7 +30,7 @@ module.exports = async (ctx) => {
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
ctx.cache.tryGet((titleOnly ? null : item.link), async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
@ -45,7 +46,8 @@ module.exports = async (ctx) => {
item.pubDate = parseDate(content('meta[property="article:published_time"]').attr('content'));
}
item.description = content('div[role="main"], .doc-content-area').html();
item.description = titleOnly ? null : content('div[role="main"], .doc-content-area').html();
item.guid = titleOnly ? `${item.link}#titleOnly` : item.link;
return item;
})

View File

@ -6,7 +6,7 @@ module.exports = {
title: 'CDRHNew',
docs: 'https://docs.rsshub.app/government.html#mei-guo-shi-pin-yao-pin-jian-du-guan-li-ju-cdrhnew',
source: ['/medical-devices/news-events-medical-devices/cdrhnew-news-and-updates', '/'],
target: '/fda/cdrh',
target: '/fda/cdrh/:titleOnly',
},
],
},

View File

@ -1,3 +1,3 @@
module.exports = function (router) {
router.get('/cdrh', require('./cdrh'));
router.get('/cdrh/:titleOnly?', require('./cdrh'));
};