Skip to content

Commit

Permalink
feat(route): add RSS3 Blog (#7566)
Browse files Browse the repository at this point in the history
Co-authored-by: DIYgod <[email protected]>
  • Loading branch information
Ethan Shen and DIYgod authored Nov 27, 2021
1 parent 40ed719 commit 83498f9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/en/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,12 @@ IPFS 网关有可能失效,那时候换成其他网关。

</Route>

## RSS3

### Blog

<Route author="nczitzk" example="/rss3/blog" path="/rss3/blog"/>

## Research Gate

### Publications
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 47 additions & 0 deletions lib/routes/rss3/blog.js
Original file line number Diff line number Diff line change
@@ -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,
};
};

1 comment on commit 83498f9

@vercel
Copy link

@vercel vercel bot commented on 83498f9 Nov 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.