Add The Verge (#852)

做自己的有缘人 Close #741
This commit is contained in:
Henry Wang
2018-10-10 15:09:42 +08:00
committed by DIYgod
parent 51f9a2aad2
commit 8899aff593
4 changed files with 91 additions and 1 deletions
+8
View File
@@ -1766,3 +1766,11 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
更多的 cid 可通过访问[官网](http://home.qutoutiao.net)切换分类,观察 url 获得。
</route>
### The Verge
<route name="The Verge" author="HenryQW" example="/verge" path="/verge">
通过提取文章全文, 以提供比官方源更佳的阅读体验.
</route>
+9 -1
View File
@@ -268,7 +268,7 @@ For airport IATA code please refer to [Wikipedia List of airports by IATA code](
<routeEn name="BBC" author="HenryQW" example="/bbc/chinese" path="/bbc/:channel?" :paramsDesc="['channel, default to `top stories`']">
Provides better reading experience (full text articles) over the official ones.
Provides a better reading experience (full text articles) over the official ones.
Support major channels, refer to [BBC RSS feeds](https://www.bbc.co.uk/news/10628494). Eg, `business` for `https://feeds.bbci.co.uk/news/business/rss.xml`.
@@ -355,3 +355,11 @@ Google Scholar has strict anti-crawling mechanism implemented, the demo below do
### Apple
<routeEn name="Exchange and Repair Extension Programs" author="metowolf HenryQW" example="/apple/exchange_repair" path="/apple/exchange_repair/:country?" :paramsDesc="['country code in apple.com URL (exception: for `United States` please use `us`), default to China `cn`']" />
### The Verge
<routeEn name="The Verge" author="HenryQW" example="/verge" path="/verge">
Provides a better reading experience (full text articles) over the official one.
</routeEn>
+3
View File
@@ -611,4 +611,7 @@ router.get('/bbc/:channel?', require('./routes/bbc/index'));
// FT 中文网
router.get('/ft/chinese/:channel?', require('./routes/ft/chinese'));
// The Verge
router.get('/verge', require('./routes/verge/index'));
module.exports = router;
+71
View File
@@ -0,0 +1,71 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const Parser = require('rss-parser');
const parser = new Parser();
module.exports = async (ctx) => {
const feed = await parser.parseURL('https://www.theverge.com/rss/index.xml');
const items = await Promise.all(
feed.items.splice(0, 10).map(async (item) => {
const response = await axios({
method: 'get',
url: item.link,
});
const $ = cheerio.load(response.data);
const content = $('div.c-entry-content');
// 处理封面图片
$('figure.e-image--hero picture > img').each((i, e) => {
let src = e.attribs.srcset;
src = src.match(/(?<=320w,).*?(?=620w)/g)[0].trim();
$(`<img src='${src}'>`).insertBefore(content[0].childNodes[0]);
});
// 处理封面视频
$('div.l-col__main > div.c-video-embed, div.c-entry-hero > div.c-video-embed').each((i, e) => {
const src = `https://volume.vox-cdn.com/embed/${e.attribs['data-volume-uuid']}?autoplay=false`;
$(`<iframe src="${src}" style="border: 0; top: 0; left: 0; width: 100%; height: 100%; position: absolute;" allowfullscreen scrolling="no"></iframe>`).insertBefore(content[0].childNodes[0]);
});
// 处理封面视频
$('div.l-col__main > div.c-video-embed--media iframe').each((i, e) => {
$(e).insertBefore(content[0].childNodes[0]);
});
// 处理文章图片
content.find('figure.e-image').each((i, e) => {
let src = $(e).find('picture > img')[0].attribs.srcset;
src = src.match(/(?<=320w,).*?(?=520w)/g)[0].trim();
$(`<img src='${src}'>`).insertBefore(e);
$(e).remove();
});
// 移除无用 DOM
content.find('aside').each((i, e) => {
$(e).remove();
});
const single = {
title: item.title,
description: content.html(),
author: item.author,
pubDate: item.pubDate,
link: item.link,
};
return Promise.resolve(single);
})
);
ctx.state.data = {
title: feed.title,
link: feed.link,
description: feed.description,
item: items,
};
};