mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
* Fix producthunt rss apolloState prop has been changed from putting the "Post" item first into the third one. * Fix the producthunt misleading '__typename' caused rss problem * refactor: simplify call
This commit is contained in:
@@ -5,22 +5,25 @@ const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got.get('https://www.producthunt.com/');
|
||||
const response = await got('https://www.producthunt.com/');
|
||||
|
||||
const data = JSON.parse(cheerio.load(response.data)('#__NEXT_DATA__').html());
|
||||
|
||||
const list = Object.values(data.props.apolloState).filter((o) => o.__typename === 'Post');
|
||||
const list = Object.values(data.props.apolloState)
|
||||
.filter((o) => o.__typename === 'Post')
|
||||
// only includes new post, not product
|
||||
.filter((o) => o.hasOwnProperty('redirectToProduct') && o.redirectToProduct === null);
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.slug, async () => {
|
||||
const detailresponse = await got.get(`https://www.producthunt.com/posts/${item.slug}`);
|
||||
const detailresponse = await got(`https://www.producthunt.com/posts/${item.slug}`);
|
||||
|
||||
const data = JSON.parse(cheerio.load(detailresponse.data)('#__NEXT_DATA__').html());
|
||||
const descData = Object.values(data.props.apolloState)[0];
|
||||
const descData = data.props.apolloState[`Post${item.id}`];
|
||||
|
||||
return {
|
||||
title: `${descData.slug} - ${item.tagline}`,
|
||||
title: `${item.slug} - ${item.tagline}`,
|
||||
description:
|
||||
descData.description +
|
||||
art(path.join(__dirname, 'templates/descImg.art'), {
|
||||
|
||||
Reference in New Issue
Block a user