mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat: 增加 Paul Graham Essays (#3589)
* feat: 增加 Paul Graham Essays * refactor: Rename router
This commit is contained in:
@@ -77,3 +77,11 @@ pageClass: routes
|
||||
### 文章
|
||||
|
||||
<Route author="junbaor SkiTiSu" example="/blogs/wangyin" path="/blogs/wangyin"/>
|
||||
|
||||
## Paul Graham 博客
|
||||
|
||||
通过提取文章全文,提供比官方源更佳的阅读体验。
|
||||
|
||||
### Essays
|
||||
|
||||
<Route author="Maecenas" example="/blogs/paulgraham" path="/blogs/paulgraham"/>
|
||||
|
||||
@@ -2042,4 +2042,7 @@ router.get('/vulture/:type', require('./routes/vulture/index'));
|
||||
// xinwenlianbo
|
||||
router.get('/xinwenlianbo/index', require('./routes/xinwenlianbo/index'));
|
||||
|
||||
// Paul Graham - Essays
|
||||
router.get('/blogs/paulgraham', require('./routes/blogs/paulgraham'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
const got = require('@/utils/got');
|
||||
const parser = require('@/utils/rss-parser');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const ProcessFeed = async (link) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
// 提取内容
|
||||
return $('font').html();
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const feed = await parser.parseURL('http://www.aaronsw.com/2002/feeds/pgessays.rss');
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items.slice(0, 5).map(async (item) => {
|
||||
const cache = await ctx.cache.get(item.link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const description = await ProcessFeed(item.link);
|
||||
|
||||
const single = {
|
||||
title: item.title,
|
||||
description,
|
||||
link: item.link,
|
||||
author: item.author,
|
||||
};
|
||||
ctx.cache.set(item.link, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: feed.title,
|
||||
link: 'http://www.paulgraham.com/articles.html',
|
||||
description: 'Essays by Paul Graham',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user