Files
RSSHub/lib/routes/rss3/blog.js
Ethan Shen 83498f959c feat(route): add RSS3 Blog (#7566)
Co-authored-by: DIYgod <diy.d.god@gmail.com>
2021-11-27 06:43:30 +00:00

48 lines
1.2 KiB
JavaScript

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,
};
};