feat(route): add World Health Organization News (#8022)

Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
Ethan Shen
2021-11-27 15:29:37 +08:00
committed by GitHub
parent 604e05b369
commit 26b39e23ef
4 changed files with 68 additions and 0 deletions

View File

@@ -562,6 +562,18 @@ Provides all of the Thrillist articles with the specified tag.
## 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 |
</Route>
### Newsroom
<RouteEn author="LogicJake" example="/who/news-room/feature-stories" path="/who/news-room/:type" :paramsDesc="['类别,可在 URL 中找到']"/>

View File

@@ -2294,6 +2294,18 @@ column 为 third 时可选的 category:
## 世界卫生组织 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 中找到']"/>

View File

@@ -1692,6 +1692,7 @@ router.get('/nintendo/system-update', lazyloadRouteHandler('./routes/nintendo/sy
// 世界卫生组织
router.get('/who/news-room/:type', lazyloadRouteHandler('./routes/who/news-room'));
router.get('/who/news/:language?', require('./routes/who/news'));
// 福利资源-met.red
router.get('/metred/fuli', lazyloadRouteHandler('./routes/metred/fuli'));

43
lib/routes/who/news.js Normal file
View File

@@ -0,0 +1,43 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const language = ctx.params.language || 'en';
const rootUrl = 'https://www.who.int';
const currentUrl = `${rootUrl}/${language === 'en' ? '' : `${language}/`}news`;
const apiUrl = `${rootUrl}/api/news/newsitems?sf_culture=${language}&$orderby=PublicationDateAndTime%20desc&$select=Title,PublicationDateAndTime,ItemDefaultUrl`;
const response = await got({
method: 'get',
url: apiUrl,
});
const list = response.data.value.map((item) => ({
title: item.Title,
link: `${currentUrl}/item/${item.ItemDefaultUrl}`,
pubDate: parseDate(item.PublicationDateAndTime),
}));
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,
});
item.description = detailResponse.data.match(/"description":"(.*)","datePublished"/)[1];
return item;
})
)
);
ctx.state.data = {
title: 'News - WHO',
link: currentUrl,
item: items,
};
};