Merge pull request #6604 from nczitzk/feature/voa

feat: add voa day in photos
This commit is contained in:
NeverBehave
2021-01-10 21:16:39 -05:00
committed by GitHub
4 changed files with 70 additions and 0 deletions
+6
View File
@@ -343,6 +343,12 @@ Provides a better reading experience (full text articles) over the official one.
</RouteEn>
## VOA News
### Day in Photos
<RouteEn author="nczitzk" example="/voa/day-photos" path="/voa/day-photos"/>
## Vulture
<RouteEn author="loganrockmore" example="/vulture/movies" path="/vulture/:tag/:excludetags?" :paramsDesc="['Tag', 'Comma-delimited list of tags. If an article includes one of these tags, it will be excluded from the RSS feed.']" />
+6
View File
@@ -577,6 +577,12 @@ IPFS 网关有可能失效,那时候换成其他网关。
<Route author="kt286" example="/topys/7" path="/topys/:category" :paramsDesc="['分类ID,可在对应页面的 URL 中找到']"/>
## VOA News
### Day in Photos
<Route author="nczitzk" example="/voa/day-photos" path="/voa/day-photos"/>
## Vulture
<Route author="loganrockmore" example="/vulture/movies" path="/vulture/:type/:excludetags?" :paramsDesc="['The sub-site name', '逗号分隔的标签列表。 如果文章包含这些标签之一,则该文章将从RSS feed中排除']">
+3
View File
@@ -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'));
+55
View File
@@ -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,
};
};