mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 01:58:11 +08:00
* fix(route): sse * refactor: migrate to v2 cont * docs: fix example * fix: typo * docs: fix tag
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
|
|
module.exports = async (ctx) => {
|
|
const slug = ctx.params.slug ?? 'latest';
|
|
|
|
const rootUrl = 'https://www.sse.com.cn';
|
|
const currentUrl = `${rootUrl}/lawandrules/guide/${slug.replace(/-/g, '/')}`;
|
|
const response = await got(currentUrl);
|
|
|
|
const $ = cheerio.load(response.data);
|
|
|
|
const list = $('.sse_list_1 dl dd')
|
|
.toArray()
|
|
.map((item) => {
|
|
item = $(item);
|
|
return {
|
|
title: item.find('a').attr('title'),
|
|
link: `${rootUrl}${item.find('a').attr('href')}`,
|
|
pubDate: parseDate(item.find('span').text().trim()),
|
|
};
|
|
});
|
|
|
|
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('.allZoom').html();
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: $('title').text(),
|
|
link: currentUrl,
|
|
item: items,
|
|
};
|
|
};
|