Skip to content

Commit

Permalink
feat(route): add World Health Organization News (#8022)
Browse files Browse the repository at this point in the history
Co-authored-by: DIYgod <[email protected]>
  • Loading branch information
Ethan Shen and DIYgod authored Nov 27, 2021
1 parent 604e05b commit 26b39e2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/en/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 中找到']"/>
12 changes: 12 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 中找到']"/>
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
43 changes: 43 additions & 0 deletions lib/routes/who/news.js
Original file line number Diff line number Diff line change
@@ -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,
};
};

1 comment on commit 26b39e2

@vercel
Copy link

@vercel vercel bot commented on 26b39e2 Nov 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.