From ba9891f578a6457183a9b4ca85b63d910ab4e978 Mon Sep 17 00:00:00 2001 From: LyleLee Date: Sun, 6 Mar 2022 20:11:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E7=BE=8E=E5=9B=BD=E7=99=BD?= =?UTF-8?q?=E5=AE=AB=E7=A7=91=E5=AD=A6=E6=8A=80=E6=9C=AF=E6=94=BF=E7=AD=96?= =?UTF-8?q?=E5=8A=9E=E5=85=AC=E5=AE=A4=20US=20Whitehouse=20Office=20Of=20S?= =?UTF-8?q?cience=20And=E2=80=A6=20(#9246)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add whitehouse/ostp 美国白宫科学技术政策办公室 US Whitehouse Office Of Science And Technology Policy * Add whitehouse OSTP, update english docs --- docs/en/government.md | 4 +++ docs/government.md | 4 +++ lib/v2/whitehouse/maintainer.js | 1 + lib/v2/whitehouse/ostp.js | 50 +++++++++++++++++++++++++++++++++ lib/v2/whitehouse/radar.js | 6 ++++ lib/v2/whitehouse/router.js | 1 + 6 files changed, 66 insertions(+) create mode 100644 lib/v2/whitehouse/ostp.js diff --git a/docs/en/government.md b/docs/en/government.md index ad7f12075..405bd460e 100644 --- a/docs/en/government.md +++ b/docs/en/government.md @@ -107,6 +107,10 @@ Fill in the English expression for the month in the Month field, eg `December` f +### Office of Science and Technology Policy + + + ## U.S. Department of the Treasury ### Press Releases diff --git a/docs/government.md b/docs/government.md index b91586f8e..01c91342e 100644 --- a/docs/government.md +++ b/docs/government.md @@ -240,6 +240,10 @@ pageClass: routes +### 科学技术政策办公室 + + + ## 美国财政部 ### 新闻稿 diff --git a/lib/v2/whitehouse/maintainer.js b/lib/v2/whitehouse/maintainer.js index 454bfa704..1e66da755 100644 --- a/lib/v2/whitehouse/maintainer.js +++ b/lib/v2/whitehouse/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/briefing-room/:category?': ['nczitzk'], + '/ostp': ['LyleLee'], }; diff --git a/lib/v2/whitehouse/ostp.js b/lib/v2/whitehouse/ostp.js new file mode 100644 index 000000000..b41d3b37a --- /dev/null +++ b/lib/v2/whitehouse/ostp.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.whitehouse.gov'; + const currentUrl = `${rootUrl}/ostp/news-updates`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.news-item__title') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('.body-content').html(); + item.pubDate = parseDate(content('time.published').attr('datetime')); + item.author = content('span.tax-links.cat-links > a').text(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: 'Whitehouse OSTP', + link: currentUrl, + description: 'Whitehouse Office of Science and Technology Policy', + item: items, + }; +}; diff --git a/lib/v2/whitehouse/radar.js b/lib/v2/whitehouse/radar.js index dcef31af0..e841a2881 100644 --- a/lib/v2/whitehouse/radar.js +++ b/lib/v2/whitehouse/radar.js @@ -8,6 +8,12 @@ module.exports = { source: ['/briefing-room/:category', '/'], target: '/whitehouse/briefing-room/:category', }, + { + title: '科技政策办公室', + docs: 'https://docs.rsshub.app/government.html#mei-guo-bai-gong-ban-gong-ting', + source: ['/ostp', '/'], + target: '/whitehouse/ostp', + }, ], }, }; diff --git a/lib/v2/whitehouse/router.js b/lib/v2/whitehouse/router.js index d815b0ce6..28403b1f7 100644 --- a/lib/v2/whitehouse/router.js +++ b/lib/v2/whitehouse/router.js @@ -1,3 +1,4 @@ module.exports = (router) => { router.get('/briefing-room/:category?', require('./briefing-room')); + router.get('/ostp', require('./ostp')); };