diff --git a/docs/README.md b/docs/README.md index 465e6df19..7f8046f6c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1766,3 +1766,11 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 更多的 cid 可通过访问[官网](http://home.qutoutiao.net)切换分类,观察 url 获得。 + +### The Verge + + + +通过提取文章全文, 以提供比官方源更佳的阅读体验. + + diff --git a/docs/en/README.md b/docs/en/README.md index bcb41b66e..2b4b17f9c 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -268,7 +268,7 @@ For airport IATA code please refer to [Wikipedia List of airports by IATA code]( -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 + +### The Verge + + + +Provides a better reading experience (full text articles) over the official one. + + diff --git a/router.js b/router.js index 89d2df199..ba0aa48ac 100644 --- a/router.js +++ b/router.js @@ -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; diff --git a/routes/verge/index.js b/routes/verge/index.js new file mode 100644 index 000000000..5a3d90768 --- /dev/null +++ b/routes/verge/index.js @@ -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(); + + $(``).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`; + + $(``).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(); + + $(``).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, + }; +};