diff --git a/docs/en/picture.md b/docs/en/picture.md index 1c29173078de2c..453e3276bf8653 100644 --- a/docs/en/picture.md +++ b/docs/en/picture.md @@ -74,7 +74,7 @@ pageClass: routes ### Home - + | Home | Hot | Popular | Recent | | ---- | --- | ------- | ------ | @@ -84,7 +84,7 @@ pageClass: routes ### Videos - + | Popular | Recent | | ------- | ------ | diff --git a/docs/new-media.md b/docs/new-media.md index 517115a45782d4..11a7734fc6cd0e 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2054,6 +2054,10 @@ column 为 third 时可选的 category: +### 公众号 (wechat-feeds 来源) + + + ### 公众号栏目 (非推送 & 历史消息) diff --git a/docs/picture.md b/docs/picture.md index 0a1b04379064aa..66e4cde5851c45 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -88,7 +88,7 @@ pageClass: routes ## Dilbert Comic Strip - + 通过提取漫画,提供比官方源更佳的阅读体验。 @@ -98,7 +98,7 @@ pageClass: routes ### Home - + | Home | Hot | Popular | Recent | | ---- | --- | ------- | ------ | @@ -108,7 +108,7 @@ pageClass: routes ### Videos - + | Popular | Recent | | ------- | ------ | diff --git a/lib/router.js b/lib/router.js index 8e7256c301c98f..0d47bf53ac40d6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -537,6 +537,7 @@ router.get('/wechat/wjdn/:id', require('./routes/tencent/wechat/wjdn')); router.get('/wechat/wxnmh/:id', require('./routes/tencent/wechat/wxnmh')); router.get('/wechat/mp/homepage/:biz/:hid/:cid?', require('./routes/tencent/wechat/mp')); router.get('/wechat/mp/msgalbum/:biz/:aid', require('./routes/tencent/wechat/msgalbum')); +router.get('/wechat/feeds/:id', require('./routes/tencent/wechat/feeds')); // All the Flight Deals router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index')); diff --git a/lib/routes/tencent/wechat/feeds.js b/lib/routes/tencent/wechat/feeds.js new file mode 100644 index 00000000000000..5347a2c87d1bef --- /dev/null +++ b/lib/routes/tencent/wechat/feeds.js @@ -0,0 +1,47 @@ +const parser = require('@/utils/rss-parser'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + const link = `https://github.com/hellodword/wechat-feeds/raw/feeds/${id}.xml`; + const feed = await parser.parseURL(link); + + const items = await Promise.all( + feed.items.map(async (item) => { + const cache = await ctx.cache.get(item.link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await got.get(item.link); + + const $ = cheerio.load(response.data); + const post = $('#js_content'); + + post.find('img').each((_, img) => { + const dataSrc = $(img).attr('data-src'); + if (dataSrc) { + $(img).attr('src', dataSrc); + } + }); + + const single = { + title: item.title, + description: post.html(), + pubDate: new Date(item.pubDate), + link: item.link, + }; + + ctx.cache.set(item.link, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${feed.title}`, + link, + description: feed.description, + item: items, + }; +};