mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 15:47:48 +08:00
* feat(router): add paradigm writing * Update lib/v2/paradigm/writing.js * Update lib/v2/paradigm/writing.js
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
|
|
const baseUrl = 'https://www.paradigm.xyz';
|
|
|
|
module.exports = async (ctx) => {
|
|
const url = `${baseUrl}/writing`;
|
|
|
|
const response = await got(url);
|
|
const $ = cheerio.load(response.data);
|
|
|
|
const nextData = JSON.parse($('#__NEXT_DATA__').text());
|
|
const buildId = nextData.buildId;
|
|
const list = nextData.props.pageProps.posts.map((item) => ({
|
|
title: item.title,
|
|
link: `${baseUrl}${item.slug}`,
|
|
api: `${baseUrl}/_next/data/${buildId}${item.slug}.json`,
|
|
author: item.authors.map((author) => author.name).join(', '),
|
|
pubDate: parseDate(item.originalDate),
|
|
category: item.tags,
|
|
}));
|
|
|
|
const items = await Promise.all(
|
|
list.map((item) =>
|
|
ctx.cache.tryGet(item.link, async () => {
|
|
const response = await got(item.api);
|
|
const $ = cheerio.load(response.data.pageProps.content, null, false);
|
|
|
|
// Remove the TOC
|
|
$('.toc').remove();
|
|
item.description = $.html();
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: 'Paradigm - Writing',
|
|
link: url,
|
|
item: items,
|
|
};
|
|
};
|