feat: add u.s. department of the treasury press releases (#6393)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen
2020-12-10 14:03:11 +00:00
committed by GitHub
co-authored by Henry Wang
parent 3b8e72b0a1
commit fc6953ae24
4 changed files with 83 additions and 1 deletions
+15 -1
View File
@@ -23,7 +23,7 @@ pageClass: routes
## The United States Trade Representative
### Press Release
### Press Releases
<RouteEn author="nczitzk" example="/ustr/press-releases" path="/ustr/press-releases/:year?/:month?" :paramsDesc="['Year, current year by default', 'Month, empty by default, show contents in all year']">
@@ -41,6 +41,20 @@ Fill in the English expression for the month in the Month field, eg `December` f
<RouteEn author="HenryQW" example="/un/scveto" path="/un/scveto"/>
## U.S. Department of the Treasury
### Press Releases
<RouteEn author="nczitzk" example="/treasury/press-releases" path="/treasury/press-releases/:category?/:title?" :paramsDesc="['Category, see below, all by default', 'Title keywords, empty by default']">
Category
| Press Releases | Statements & Remarks | Readouts | Testimonies |
| -------------- | -------------------- | -------- | ----------- |
| all | statements-remarks | readouts | testimonies |
</RouteEn>
## World Trade Organization
### Dispute settlement news
+14
View File
@@ -77,6 +77,20 @@ pageClass: routes
<Route author="HenryQW" example="/un/scveto" path="/un/scveto"/>
## 美国财政部
### 新闻稿
<Route author="nczitzk" example="/treasury/press-releases" path="/treasury/press-releases/:category?/:title?" :paramsDesc="['分类,见下表,默认为全部', '标题关键字,默认为空']">
分类
| Press Releases | Statements & Remarks | Readouts | Testimonies |
| -------------- | -------------------- | -------- | ----------- |
| all | statements-remarks | readouts | testimonies |
</Route>
## 美国联邦最高法院
### 辩论音频
+3
View File
@@ -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'));
+51
View File
@@ -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,
};
};