mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 05:59:00 +08:00
fix: hedwig.pub (#4588)
This commit is contained in:
@@ -1,55 +1,38 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const md = require('markdown-it')({
|
||||
html: true,
|
||||
});
|
||||
const dayjs = require('dayjs');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type;
|
||||
|
||||
const url = 'https://' + `${type}` + '.hedwig.pub';
|
||||
const url = `https://${type}.hedwig.pub`;
|
||||
const res = await got({
|
||||
method: 'get',
|
||||
url: url,
|
||||
});
|
||||
const $ = cheerio.load(res.data);
|
||||
const title = $('div[class="StyledBox-sc-13pk1d4-0 heWGCm"]').find('h1').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 content = JSON.parse($('#__NEXT_DATA__')[0].children[0].data);
|
||||
const title = $('title').text();
|
||||
|
||||
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 = {
|
||||
title: 'Ⓙ Hedwig - ' + title,
|
||||
link: 'https://' + `${type}` + '.hedwig.pub',
|
||||
item: result,
|
||||
title: `Ⓙ Hedwig - ${title}`,
|
||||
description: content.props.pageProps.newsletter.about,
|
||||
link: `https://${type}.hedwig.pub`,
|
||||
item: list,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user