mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-16 19:50:01 +08:00
48 lines
1.2 KiB
JavaScript
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,
|
|
};
|
|
};
|