Files
RSSHub/lib/v2/eagle/blog.js
Fatpandac cff988ad9f feat(route): add Eagle's blog and refactor to V2 (#9546)
* feat(route): add Eagle's blog and refactor to V2

* fix: remove deprecated eagle radar rules

* fix: changelog date and guid

* fix(route): add language option
2022-04-17 21:24:17 +08:00

48 lines
1.5 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const cateList = ['all', 'design-resources', 'learn-design', 'inside-eagle'];
module.exports = async (ctx) => {
let cate = ctx.params.cate ?? 'all';
let language = ctx.params.language ?? 'cn';
if (cateList.indexOf(cate) === -1) {
language = cate;
cate = 'all';
}
const host = `https://${language}.eagle.cool`;
const url = `${host}/blog/${cate === 'all' ? '' : cate}`;
const response = await got(url);
const $ = cheerio.load(response.data);
const title = $('div.categories-list > div > div > div > ul > li.active').text();
const list = $('div.post-item')
.map((_index, item) => ({
title: $(item).find('div.title').text(),
link: new URL($(item).find('a').attr('href'), host).href,
pubDate: parseDate($(item).find('div.metas > a > span').text().replace('・', '')),
}))
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link);
const content = cheerio.load(detailResponse.data);
item.description = content('div.post-html').html();
return item;
})
)
);
ctx.state.data = {
title: `eagle - ${title}`,
link: url,
item: items,
};
};