feat: add the united states trade representative press release (#6384)

This commit is contained in:
Ethan Shen 2020-12-10 06:27:26 +08:00 committed by GitHub
parent 4f95d5ed7b
commit baaa141dcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 0 deletions

View File

@ -21,6 +21,20 @@ pageClass: routes
<RouteEn author="nczitzk" example="/us/supremecourt/argument_audio" path="/us/supremecourt/argument_audio/:year?" :paramsDesc="['Year, current year by default']"/>
## The United States Trade Representative
### Press Release
<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']">
::: tip Tip
Fill in the English expression for the month in the Month field, eg `December` for the 12th Month。
:::
</RouteEn>
## United Nations
### Security Council Vetoed a Resolution

View File

@ -83,6 +83,20 @@ pageClass: routes
<Route author="nczitzk" example="/us/supremecourt/argument_audio" path="/us/supremecourt/argument_audio/:year?" :paramsDesc="['年份,默认为当前年份']"/>
## 美国贸易代表办公室
### 新闻稿
<Route author="nczitzk" example="/ustr/press-releases" path="/ustr/press-releases/:year?/:month?" :paramsDesc="['年份,默认为当前年份', '月份,默认为空,即全年']">
::: tip 提示
月份处填写该月的英语表达,如 12 月 应填入 `December`
:::
</Route>
## 美国中央情报局
### 年度信息自由法报告

View File

@ -3670,4 +3670,7 @@ router.get('/proletar/:type?/:id?', require('./routes/proletar/index'));
// QTTabBar
router.get('/qttabbar/change-log', require('./routes/qttabbar/change-log'));
// 美国贸易代表办公室
router.get('/ustr/press-releases/:year?/:month?', require('./routes/us/ustr/press-releases'));
module.exports = router;

View File

@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const year = ctx.params.year || new Date().getFullYear().toString();
const month = ctx.params.month || '';
const rootUrl = 'https://ustr.gov';
const currentUrl = `${rootUrl}/about-us/policy-offices/press-office/press-releases/${year}/${month}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('ul.listing li a')
.slice(0, 15)
.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-body').html();
item.pubDate = new Date(content('.title-underline').next().text()).toUTCString();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};