diff --git a/docs/en/new-media.md b/docs/en/new-media.md index e16ae2b774a3e4..0762f1bdab481e 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -562,6 +562,18 @@ Provides all of the Thrillist articles with the specified tag. ## World Health Organization | WHO +### News + + + +Language + +| English | العربية | 中文 | Français | Русский | Español | Português | +| ------- | ------- | ---- | -------- | ------- | ------- | --------- | +| en | ar | zh | fr | ru | es | pt | + + + ### Newsroom diff --git a/docs/new-media.md b/docs/new-media.md index 0dc10836c4d0a9..790ee20c404ee1 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2294,6 +2294,18 @@ column 为 third 时可选的 category: ## 世界卫生组织 WHO +### 新闻稿 + + + +语言 + +| English | العربية | 中文 | Français | Русский | Español | Português | +| ------- | ------- | ---- | -------- | ------- | ------- | --------- | +| en | ar | zh | fr | ru | es | pt | + + + ### 媒体中心 diff --git a/lib/router.js b/lib/router.js index a4dcd40cf65340..e3ab894528bb6b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/who/news.js b/lib/routes/who/news.js new file mode 100644 index 00000000000000..1bc568986d9b10 --- /dev/null +++ b/lib/routes/who/news.js @@ -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, + }; +};