diff --git a/docs/en/government.md b/docs/en/government.md index 6572abbe6f..9135e328a3 100644 --- a/docs/en/government.md +++ b/docs/en/government.md @@ -23,7 +23,7 @@ pageClass: routes ## The United States Trade Representative -### Press Release +### Press Releases @@ -41,6 +41,20 @@ Fill in the English expression for the month in the Month field, eg `December` f +## U.S. Department of the Treasury + +### Press Releases + + + +Category + +| Press Releases | Statements & Remarks | Readouts | Testimonies | +| -------------- | -------------------- | -------- | ----------- | +| all | statements-remarks | readouts | testimonies | + + + ## World Trade Organization ### Dispute settlement news diff --git a/docs/government.md b/docs/government.md index 81abef700b..059809a443 100644 --- a/docs/government.md +++ b/docs/government.md @@ -77,6 +77,20 @@ pageClass: routes +## 美国财政部 + +### 新闻稿 + + + +分类 + +| Press Releases | Statements & Remarks | Readouts | Testimonies | +| -------------- | -------------------- | -------- | ----------- | +| all | statements-remarks | readouts | testimonies | + + + ## 美国联邦最高法院 ### 辩论音频 diff --git a/lib/router.js b/lib/router.js index 3c84a87d75..4d18e6df37 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3676,6 +3676,9 @@ router.get('/cool18/:id?/:type?/:keyword?', require('./routes/cool18/index')); // 美国贸易代表办公室 router.get('/ustr/press-releases/:year?/:month?', require('./routes/us/ustr/press-releases')); +// 美国财政部 +router.get('/treasury/press-releases/:category?/:title?', require('./routes/us/treasury/press-releases')); + // Bandisoft router.get('/bandisoft/:id?/:lang?', require('./routes/bandisoft/index')); diff --git a/lib/routes/us/treasury/press-releases.js b/lib/routes/us/treasury/press-releases.js new file mode 100644 index 0000000000..e94fee20d2 --- /dev/null +++ b/lib/routes/us/treasury/press-releases.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const title = ctx.params.title || ''; + const category = ctx.params.category || 'all'; + + const rootUrl = 'https://home.treasury.gov'; + const currentUrl = `${rootUrl}/news/press-releases${category === 'all' ? '' : `/${category}`}${title === '' ? '' : `?title=${title}`}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.featured-stories__headline a') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('.field--name-field-news-body').html(); + item.pubDate = new Date(content('time').attr('datetime')).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};