From 7aa76219f0768022ff142a9e335a37e0e32ecf00 Mon Sep 17 00:00:00 2001 From: terrytw <24227628+terrytw@users.noreply.github.com> Date: Mon, 8 Aug 2022 22:48:00 +0800 Subject: [PATCH] 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 --- docs/government.md | 2 +- lib/v2/fda/cdrh.js | 6 ++++-- lib/v2/fda/radar.js | 2 +- lib/v2/fda/router.js | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/government.md b/docs/government.md index f3ba85f68..aa948e548 100644 --- a/docs/government.md +++ b/docs/government.md @@ -400,7 +400,7 @@ pageClass: routes ### CDRHNew - + ## 美国中央情报局 diff --git a/lib/v2/fda/cdrh.js b/lib/v2/fda/cdrh.js index c236d0613..8a197c9f6 100644 --- a/lib/v2/fda/cdrh.js +++ b/lib/v2/fda/cdrh.js @@ -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; }) diff --git a/lib/v2/fda/radar.js b/lib/v2/fda/radar.js index a84167db3..18494334b 100644 --- a/lib/v2/fda/radar.js +++ b/lib/v2/fda/radar.js @@ -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', }, ], }, diff --git a/lib/v2/fda/router.js b/lib/v2/fda/router.js index b0f07a5ff..71a6566e0 100644 --- a/lib/v2/fda/router.js +++ b/lib/v2/fda/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get('/cdrh', require('./cdrh')); + router.get('/cdrh/:titleOnly?', require('./cdrh')); };