fix(route): World Health Organization Newsroom (#8012)
* fix(route): World Health Organization Newsroom * refactor: migrate to v2 Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
parent
0f503e55e0
commit
171ee3b006
|
|
@ -127,6 +127,50 @@ Category
|
|||
|
||||
<RouteEn author="HenryQW" example="/un/scveto" path="/un/scveto"/>
|
||||
|
||||
## World Health Organization | WHO
|
||||
|
||||
### News
|
||||
|
||||
<RouteEn author="nczitzk" example="/who/news" path="/who/news/:language?" :paramsDesc="['Language, see below, English by default']">
|
||||
|
||||
Language
|
||||
|
||||
| English | العربية | 中文 | Français | Русский | Español | Português |
|
||||
| ------- | ------- | ---- | -------- | ------- | ------- | --------- |
|
||||
| en | ar | zh | fr | ru | es | pt |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
### Newsroom
|
||||
|
||||
<RouteEn author="LogicJake nczitzk" example="/who/news-room/feature-stories" path="/who/news-room/:category?/:language?" :paramsDesc="['Category, see below, Feature stories by default', 'Language, see below, English by default']">
|
||||
|
||||
Category
|
||||
|
||||
| Feature stories | Commentaries |
|
||||
| --------------- | ------------ |
|
||||
| feature-stories | commentaries |
|
||||
|
||||
Language
|
||||
|
||||
| English | العربية | 中文 | Français | Русский | Español | Português |
|
||||
| ------- | ------- | ---- | -------- | ------- | ------- | --------- |
|
||||
| en | ar | zh | fr | ru | es | pt |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
### Speeches
|
||||
|
||||
<RouteEn author="nczitzk" example="/who/speeches" path="/who/speeches/:language?" :paramsDesc="['Language, see below, English by default']">
|
||||
|
||||
Language
|
||||
|
||||
| English | العربية | 中文 | Français | Русский | Español | Português |
|
||||
| ------- | ------- | ---- | -------- | ------- | ------- | --------- |
|
||||
| en | ar | zh | fr | ru | es | pt |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## World Trade Organization
|
||||
|
||||
### Dispute settlement news
|
||||
|
|
|
|||
|
|
@ -647,33 +647,3 @@ Provides all of the Thrillist articles with the specified tag.
|
|||
### Archive
|
||||
|
||||
<RouteEn author="nczitzk" example="/worldhappiness/archive" path="/worldhappiness/archive"/>
|
||||
|
||||
## World Health Organization | WHO
|
||||
|
||||
### News
|
||||
|
||||
<RouteEn author="nczitzk" example="/who/news" path="/who/news/:language?" :paramsDesc="['Language, see below, English by default']">
|
||||
|
||||
Language
|
||||
|
||||
| English | العربية | 中文 | Français | Русский | Español | Português |
|
||||
| ------- | ------- | ---- | -------- | ------- | ------- | --------- |
|
||||
| en | ar | zh | fr | ru | es | pt |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
### Newsroom
|
||||
|
||||
<RouteEn author="LogicJake" example="/who/news-room/feature-stories" path="/who/news-room/:type" :paramsDesc="['类别,可在 URL 中找到']"/>
|
||||
|
||||
### Speeches
|
||||
|
||||
<RouteEn author="nczitzk" example="/who/speeches" path="/who/speeches/:language?" :paramsDesc="['Language, see below, English by default']">
|
||||
|
||||
Language
|
||||
|
||||
| English | العربية | 中文 | Français | Русский | Español | Português |
|
||||
| ------- | ------- | ---- | -------- | ------- | ------- | --------- |
|
||||
| en | ar | zh | fr | ru | es | pt |
|
||||
|
||||
</RouteEn>
|
||||
|
|
|
|||
|
|
@ -314,6 +314,50 @@ pageClass: routes
|
|||
|
||||
<Route author="nczitzk" example="/wto/dispute-settlement" path="/wto/dispute-settlement/:year?" :paramsDesc="['年份,默认为当前年份']"/>
|
||||
|
||||
## 世界卫生组织 WHO
|
||||
|
||||
### 新闻稿
|
||||
|
||||
<Route author="nczitzk" example="/who/news" path="/who/news/:language?" :paramsDesc="['语言,见下表,默认为英语']">
|
||||
|
||||
语言
|
||||
|
||||
| English | العربية | 中文 | Français | Русский | Español | Português |
|
||||
| ------- | ------- | -- | -------- | ------- | ------- | --------- |
|
||||
| en | ar | zh | fr | ru | es | pt |
|
||||
|
||||
</Route>
|
||||
|
||||
### 媒体中心
|
||||
|
||||
<Route author="LogicJake nczitzk" example="/who/news-room/feature-stories" path="/who/news-room/:category?/:language?" :paramsDesc="['分类,见下表,默认为特写故事', '语言,见下表,默认为英语']">
|
||||
|
||||
分类
|
||||
|
||||
| 特写故事 | 评论 |
|
||||
| --------------- | ------------ |
|
||||
| feature-stories | commentaries |
|
||||
|
||||
语言
|
||||
|
||||
| English | العربية | 中文 | Français | Русский | Español | Português |
|
||||
| ------- | ------- | -- | -------- | ------- | ------- | --------- |
|
||||
| en | ar | zh | fr | ru | es | pt |
|
||||
|
||||
</Route>
|
||||
|
||||
### 总干事的讲话
|
||||
|
||||
<Route author="nczitzk" example="/who/speeches" path="/who/speeches/:language?" :paramsDesc="['语言,见下表,默认为英语']">
|
||||
|
||||
语言
|
||||
|
||||
| English | العربية | 中文 | Français | Русский | Español | Português |
|
||||
| ------- | ------- | -- | -------- | ------- | ------- | --------- |
|
||||
| en | ar | zh | fr | ru | es | pt |
|
||||
|
||||
</Route>
|
||||
|
||||
## 苏州市人民政府
|
||||
|
||||
### 政府新闻
|
||||
|
|
|
|||
|
|
@ -2938,36 +2938,6 @@ column 为 third 时可选的 category:
|
|||
|
||||
</Route>
|
||||
|
||||
## 世界卫生组织 WHO
|
||||
|
||||
### 新闻稿
|
||||
|
||||
<Route author="nczitzk" example="/who/news" path="/who/news/:language?" :paramsDesc="['语言,见下表,默认为英语']">
|
||||
|
||||
语言
|
||||
|
||||
| English | العربية | 中文 | Français | Русский | Español | Português |
|
||||
| ------- | ------- | -- | -------- | ------- | ------- | --------- |
|
||||
| en | ar | zh | fr | ru | es | pt |
|
||||
|
||||
</Route>
|
||||
|
||||
### 媒体中心
|
||||
|
||||
<Route author="LogicJake" example="/who/news-room/feature-stories" path="/who/news-room/:type" :paramsDesc="['类别,可在 URL 中找到']"/>
|
||||
|
||||
### 总干事的讲话
|
||||
|
||||
<Route author="nczitzk" example="/who/speeches" path="/who/speeches/:language?" :paramsDesc="['语言,见下表,默认为英语']">
|
||||
|
||||
语言
|
||||
|
||||
| English | العربية | 中文 | Français | Русский | Español | Português |
|
||||
| ------- | ------- | -- | -------- | ------- | ------- | --------- |
|
||||
| en | ar | zh | fr | ru | es | pt |
|
||||
|
||||
</Route>
|
||||
|
||||
## 数英网
|
||||
|
||||
### 数英网最新文章
|
||||
|
|
|
|||
|
|
@ -1615,10 +1615,10 @@ router.get('/nintendo/news/china', lazyloadRouteHandler('./routes/nintendo/news_
|
|||
router.get('/nintendo/direct', lazyloadRouteHandler('./routes/nintendo/direct'));
|
||||
router.get('/nintendo/system-update', lazyloadRouteHandler('./routes/nintendo/system-update'));
|
||||
|
||||
// 世界卫生组织
|
||||
router.get('/who/news-room/:type', lazyloadRouteHandler('./routes/who/news-room'));
|
||||
router.get('/who/speeches/:language?', lazyloadRouteHandler('./routes/who/speeches'));
|
||||
router.get('/who/news/:language?', lazyloadRouteHandler('./routes/who/news'));
|
||||
// 世界卫生组织 migrated to v2
|
||||
// router.get('/who/news-room/:category?/:language?', lazyloadRouteHandler('./routes/who/news-room'));
|
||||
// router.get('/who/speeches/:language?', lazyloadRouteHandler('./routes/who/speeches'));
|
||||
// router.get('/who/news/:language?', lazyloadRouteHandler('./routes/who/news'));
|
||||
|
||||
// 福利资源-met.red
|
||||
router.get('/metred/fuli', lazyloadRouteHandler('./routes/metred/fuli'));
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const url = require('url');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const host = 'https://www.who.int/';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type;
|
||||
|
||||
const link = url.resolve('https://www.who.int/zh/news-room/', type);
|
||||
const response = await got.get(encodeURI(link));
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('div.list-view--item');
|
||||
const title = $('ul.sf-breadscrumb.breadcrumb li.active').text();
|
||||
const out = await Promise.all(
|
||||
list
|
||||
.map(async (index, elem) => {
|
||||
const $elem = $(elem);
|
||||
const title = $elem.find('p').text();
|
||||
const link = url.resolve(host, $elem.find('a').attr('href'));
|
||||
const pubDate = parseDate($elem.find('.timestamp').text(), 'YYYY年M月D日');
|
||||
|
||||
const item = {
|
||||
title,
|
||||
pubDate,
|
||||
link: encodeURI(link),
|
||||
};
|
||||
|
||||
const key = link;
|
||||
const value = await ctx.cache.get(key);
|
||||
if (value) {
|
||||
item.description = value;
|
||||
} else {
|
||||
const detail = await got.get(item.link);
|
||||
const data = detail.data;
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
item.description = $('article')
|
||||
.html()
|
||||
.replace(/src="\//g, `src="${host}`);
|
||||
ctx.cache.set(key, item.description);
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
.get()
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `世界卫生组织媒体中心-${title}`,
|
||||
link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
'/news/:language?': ['nczitzk'],
|
||||
'/news-room/:category?/:language?': ['LogicJake', 'nczitzk'],
|
||||
'/speeches/:language?': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category ?? 'feature-stories';
|
||||
const language = ctx.params.language ?? '';
|
||||
|
||||
const rootUrl = 'https://www.who.int';
|
||||
const currentUrl = `${rootUrl}/${language ? `${language}/` : ''}news-room/${category}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let list = $('.list-view--item a');
|
||||
|
||||
if (list.length === 0) {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `${rootUrl}/api/hubs/${category.replace(/-/g, '')}?sf_culture=zh&$orderby=PublicationDateAndTime%20desc&$select=Title,PublicationDateAndTime,ItemDefaultUrl&$top=30`,
|
||||
});
|
||||
|
||||
list = response.data.value.map((item) => ({
|
||||
title: item.Title,
|
||||
link: `${currentUrl}/detail/${item.ItemDefaultUrl}`,
|
||||
pubDate: parseDate(item.PublicationDateAndTime),
|
||||
}));
|
||||
} else {
|
||||
list = list
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const link = item.attr('href');
|
||||
|
||||
return {
|
||||
link: `${link.indexOf('http') === 0 ? '' : 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 matches = detailResponse.data.match(/"headline":"(.*)","description":"(.*)","datePublished":"(.*)","image"/);
|
||||
|
||||
if (matches) {
|
||||
item.title = matches[1];
|
||||
item.description = matches[2];
|
||||
item.pubDate = parseDate(matches[3]);
|
||||
} else {
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.sf-content-block').html();
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('meta[property="og:title"]').attr('content')} - WHO`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -2,7 +2,7 @@ const got = require('@/utils/got');
|
|||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const language = ctx.params.language || 'en';
|
||||
const language = ctx.params.language ?? 'en';
|
||||
|
||||
const rootUrl = 'https://www.who.int';
|
||||
const currentUrl = `${rootUrl}/${language === 'en' ? '' : `${language}/`}news`;
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
module.exports = {
|
||||
'who.int': {
|
||||
_name: '世界卫生组织 WHO',
|
||||
'.': [
|
||||
{
|
||||
title: '新闻稿',
|
||||
docs: 'https://docs.rsshub.app/government.html#shi-jie-wei-sheng-zu-zhi-who',
|
||||
source: '/news',
|
||||
target: '/who/news',
|
||||
},
|
||||
{
|
||||
title: '媒体中心',
|
||||
docs: 'https://docs.rsshub.app/government.html#shi-jie-wei-sheng-zu-zhi-who',
|
||||
source: '/news-room/:type',
|
||||
target: '/who/news-room/:type',
|
||||
},
|
||||
{
|
||||
title: '总干事的讲话',
|
||||
docs: 'https://docs.rsshub.app/government.html#shi-jie-wei-sheng-zu-zhi-who',
|
||||
source: '/director-general/speeches',
|
||||
target: '/who/speeches',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/news/:language?', require('./news'));
|
||||
router.get('/news-room/:category?/:language?', require('./news-room'));
|
||||
router.get('/speeches/:language?', require('./speeches'));
|
||||
};
|
||||
Loading…
Reference in New Issue