diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 4ef729a37d..51ea8aed4e 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -343,6 +343,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 3635e291c7..1dd27e7377 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -577,6 +577,12 @@ IPFS 网关有可能失效,那时候换成其他网关。 +## VOA News + +### Day in Photos + + + ## Vulture diff --git a/lib/router.js b/lib/router.js index 82cc50463a..112c5292d9 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3790,6 +3790,9 @@ 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')); + // 留园网 router.get('/6park/:id?/:type?/:keyword?', require('./routes/6park/index')); 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, + }; +};