mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-10 07:12:51 +08:00
fix: hedwig.pub (#4588)
This commit is contained in:
@@ -1,55 +1,38 @@
|
|||||||
const got = require('@/utils/got');
|
const got = require('@/utils/got');
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
|
const md = require('markdown-it')({
|
||||||
|
html: true,
|
||||||
|
});
|
||||||
|
const dayjs = require('dayjs');
|
||||||
|
|
||||||
module.exports = async (ctx) => {
|
module.exports = async (ctx) => {
|
||||||
const type = ctx.params.type;
|
const type = ctx.params.type;
|
||||||
|
|
||||||
const url = 'https://' + `${type}` + '.hedwig.pub';
|
const url = `https://${type}.hedwig.pub`;
|
||||||
const res = await got({
|
const res = await got({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: url,
|
url: url,
|
||||||
});
|
});
|
||||||
const $ = cheerio.load(res.data);
|
const $ = cheerio.load(res.data);
|
||||||
const title = $('div[class="StyledBox-sc-13pk1d4-0 heWGCm"]').find('h1').text();
|
const content = JSON.parse($('#__NEXT_DATA__')[0].children[0].data);
|
||||||
|
const title = $('title').text();
|
||||||
const list = $('div[class="StyledBox-sc-13pk1d4-0 czKiZd"]')
|
|
||||||
.find('div[class="StyledBox-sc-13pk1d4-0 czKiZd"]')
|
|
||||||
.find('div[class="StyledBox-sc-13pk1d4-0 czKiZd"]')
|
|
||||||
.map((i, e) => {
|
|
||||||
const element = $(e);
|
|
||||||
const title = element.find('a').find('h3').text();
|
|
||||||
const link = url + element.find('a').attr('href');
|
|
||||||
return {
|
|
||||||
title: title,
|
|
||||||
description: '',
|
|
||||||
link: link,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.get();
|
|
||||||
|
|
||||||
const result = await Promise.all(
|
|
||||||
list.map(async (item) => {
|
|
||||||
const link = item.link;
|
|
||||||
|
|
||||||
const cache = await ctx.cache.get(link);
|
|
||||||
if (cache) {
|
|
||||||
return Promise.resolve(JSON.parse(cache));
|
|
||||||
}
|
|
||||||
|
|
||||||
const itemReponse = await got.get(link);
|
|
||||||
const itemElement = cheerio.load(itemReponse.data);
|
|
||||||
// Remove duplicate title
|
|
||||||
itemElement('.StyledBox-sc-13pk1d4-0 .bpdfin').find('h1[class="StyledHeading-sc-1rdh4aw-0 kIYNxP"]').remove();
|
|
||||||
item.description = itemElement('.StyledBox-sc-13pk1d4-0 .bpdfin').html();
|
|
||||||
|
|
||||||
ctx.cache.set(link, JSON.stringify(item));
|
|
||||||
return Promise.resolve(item);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
|
const list = content.props.pageProps.issuesByNewsletter.map((item) => {
|
||||||
|
let description = '';
|
||||||
|
item.blocks.forEach((block) => {
|
||||||
|
description += md.render(block.markdown.text);
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
title: item.subject,
|
||||||
|
description: description,
|
||||||
|
pubDate: dayjs(`${item.publishAt} +0800`, "YYYY-MM-DD'T'HH:mm:ss.SSS'Z'").toString(),
|
||||||
|
link: `https://${type}.hedwig.pub/i/${item.urlFriendlyName}`,
|
||||||
|
};
|
||||||
|
});
|
||||||
ctx.state.data = {
|
ctx.state.data = {
|
||||||
title: 'Ⓙ Hedwig - ' + title,
|
title: `Ⓙ Hedwig - ${title}`,
|
||||||
link: 'https://' + `${type}` + '.hedwig.pub',
|
description: content.props.pageProps.newsletter.about,
|
||||||
item: result,
|
link: `https://${type}.hedwig.pub`,
|
||||||
|
item: list,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user