Files
RSSHub/lib/v2/mysql/release.js
Ethan Shen ce1e74323c feat(route): add MySQL Release Notes (#9929)
* feat(route): add MySQL Release Notes

* ci: trigger build
2022-06-10 13:03:14 +08:00

56 lines
1.4 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const version = ctx.params.version ?? '8.0';
const rootUrl = 'https://dev.mysql.com';
const currentUrl = `${rootUrl}/doc/relnotes/mysql/${version}/en`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let items = $('dt span a')
.slice(1, -1)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: `${currentUrl}/${item.attr('href')}`,
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('.indexterm').remove();
content('.titlepage').first().remove();
content('.itemizedlist').first().remove();
item.description = content('#docs-body .section').html();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};