feat: add china labour watch reports (#6364)

This commit is contained in:
Ethan Shen
2020-12-06 18:18:09 +00:00
committed by GitHub
parent e60baf68ee
commit 44e9c3fa67
4 changed files with 81 additions and 0 deletions
+12
View File
@@ -260,3 +260,15 @@ Provides a better reading experience (full text articles) over the official one.
### Newsroom
<RouteEn author="LogicJake" example="/who/news-room/feature-stories" path="/who/news-room/:type" :paramsDesc="['类别,可在 URL 中找到']"/>
## China Labour Watch
### Reports
<RouteEn author="nczitzk" example="/chinalaborwatch/reports" path="/chinalaborwatch/reports/:lang?/:industry?" :paramsDesc="['Language, English by default, or `cn` as Simplified Chinese', 'Industry id, see below, all by default']">
| All | Automotive | Cookware | Electronics | Footwear | Furniture | Garment | General | Printing | Retail | Toys |
| - | - | - | - | - | - | - | - | - | - | - |
| | 2 | 6 | 14 | 3 | 4 | 10 | 8 | 1 | 9 | 7 |
</RouteEn>
+12
View File
@@ -1897,6 +1897,18 @@ QueryString:
<Route author="HenryQW" example="/zzz" path="/zzz/index"/>
## 中国劳工观察
### 调查报告
<Route author="nczitzk" example="/chinalaborwatch/reports" path="/chinalaborwatch/reports/:lang?/:industry?" :paramsDesc="['语言,默认为英语,可选 `cn` 即 简体中文', '行业 id,见下表,默认为全部']">
| 全部 | 制鞋 | 印刷 | 厨具 | 家具 | 服饰 | 汽车制造 | 玩具 | 电子产品 | 综合 | 零售 |
| ---- | ---- | ---- | ---- | ---- | ---- | -------- | ---- | -------- | ---- | ---- |
| | 2 | 6 | 14 | 3 | 4 | 10 | 8 | 1 | 9 | 7 |
</Route>
## 中国劳工通讯
### 评论与特写
+3
View File
@@ -3519,6 +3519,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
// 中国劳工观察
router.get('/chinalaborwatch/reports/:lang?/:industry?', require('./routes/chinalaborwatch/reports'));
// 美国中央情报局
router.get('/cia/foia-annual-report', require('./routes/us/cia/foia-annual-report'));
+54
View File
@@ -0,0 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const lang = ctx.params.lang || '';
const industry = ctx.params.industry || '';
const rootUrl = 'http://www.chinalaborwatch.org';
const currentUrl = `${rootUrl}/${lang === '' ? '' : 'cn/'}reports${industry === '' ? '' : `/industry/${industry}`}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.Alt1 a, .Alt2 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.pubDate = new Date(content('#ContentPlaceHolder1_LabelDate').text().replace(/年|月/g, '-').replace('日', '')).toUTCString();
content('h1, #ContentPlaceHolder1_LabelDate').remove();
item.description = content('.mainContent').html();
return item;
})
)
);
ctx.state.data = {
title: `${$('title').text()} - ${lang === '' ? 'China Labour Watch' : '中国劳工观察'}`,
link: currentUrl,
item: items,
};
};