feat(route): add RSS3 Blog (#7566)

Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
Ethan Shen
2021-11-27 06:43:30 +00:00
committed by GitHub
co-authored by DIYgod
parent 40ed719afb
commit 83498f959c
4 changed files with 62 additions and 0 deletions
+6
View File
@@ -372,6 +372,12 @@ Compared to the official one, this feed:
</RouteEn>
## RSS3
### Blog
<RouteEn author="nczitzk" example="/rss3/blog" path="/rss3/blog"/>
## Research Gate
### Publications
+6
View File
@@ -713,6 +713,12 @@ IPFS 网关有可能失效,那时候换成其他网关。
</Route>
## RSS3
### Blog
<Route author="nczitzk" example="/rss3/blog" path="/rss3/blog"/>
## Research Gate
### Publications
+3
View File
@@ -4218,4 +4218,7 @@ router.get('/researchgate/publications/:id', require('./routes/researchgate/publ
// QuestMobile
router.get('/questmobile/report/:category?/:label?', require('./routes/questmobile/report'));
// RSS3
router.get('/rss3/blog', require('./routes/rss3/blog'));
module.exports = router;
+47
View File
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://blog.rss3.io';
const response = await got({
method: 'get',
url: rootUrl,
});
const $ = cheerio.load(response.data);
const list = $('h1 a')
.slice(0, 15)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.post-content').html();
item.pubDate = Date.parse(content('small time').attr('datetime'));
return item;
})
)
);
ctx.state.data = {
title: 'Blog - RSS3',
link: rootUrl,
item: items,
};
};