From 7e8c7142df4c5fc9ecb059c66f6b576421359947 Mon Sep 17 00:00:00 2001 From: nczitzk Date: Mon, 4 Jan 2021 19:49:12 +0800 Subject: [PATCH 1/2] feat: add voa day in photos --- docs/en/new-media.md | 6 ++++ docs/new-media.md | 6 ++++ lib/router.js | 3 ++ lib/routes/voa/day-photos.js | 55 ++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 lib/routes/voa/day-photos.js diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 070815cbe9..5554b77ad3 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -335,6 +335,12 @@ Provides a better reading experience (full text articles) over the official one. +## VOA News + +### Day in Photos + + + ## Vulture diff --git a/docs/new-media.md b/docs/new-media.md index dea896d573..a32e6cd153 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -569,6 +569,12 @@ IPFS 网关有可能失效,那时候换成其他网关。 +## VOA News + +### Day in Photos + + + ## Vulture diff --git a/lib/router.js b/lib/router.js index 5bb0f656c3..34409e97d2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3780,4 +3780,7 @@ router.get('/nace/blog/:sort?', require('./routes/nace/blog')); // Caixin Latest router.get('/caixin/latest', require('./routes/caixin/latest')); +// VOA News +router.get('/voa/day-photos', require('./routes/voa/day-photos')); + module.exports = router; diff --git a/lib/routes/voa/day-photos.js b/lib/routes/voa/day-photos.js new file mode 100644 index 0000000000..79a4c7751a --- /dev/null +++ b/lib/routes/voa/day-photos.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.voanews.com'; + const currentUrl = `${rootUrl}/day-photos`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.teaser__title-link') + .slice(0, 15) + .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); + + content('img').each(function () { + content(this).attr('src', content(this).attr('data-src')); + content(this).removeAttr('data-src'); + }); + + content('noscript').remove(); + + item.description = content('.multimedia-gallery__items').html(); + item.pubDate = new Date(content('.page-header__meta-item').text()).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; From 185efa96461a1471e335d0160fb923edb566a707 Mon Sep 17 00:00:00 2001 From: nczitzk Date: Mon, 4 Jan 2021 19:52:15 +0800 Subject: [PATCH 2/2] fix typo --- docs/en/new-media.md | 2 +- docs/new-media.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 5554b77ad3..153409230b 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -339,7 +339,7 @@ Provides a better reading experience (full text articles) over the official one. ### Day in Photos - + ## Vulture diff --git a/docs/new-media.md b/docs/new-media.md index a32e6cd153..dedba766f7 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -573,7 +573,7 @@ IPFS 网关有可能失效,那时候换成其他网关。 ### Day in Photos - + ## Vulture