Files
RSSHub/lib/v2/sse/lawandrules.js
Tony 5c50f81bcf fix(route): sse (#10779)
* fix(route): sse

* refactor: migrate to v2 cont

* docs: fix example

* fix: typo

* docs: fix tag
2022-09-14 03:27:16 +08:00

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