forked from chengxuanying/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): 微信公众号新增 wechat-feeds 来源 (DIYgod#7419)
Co-authored-by: GitHub Action <[email protected]>
- Loading branch information
1 parent
ac0e922
commit 39db632
Showing
5 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
}; |