fix(route): producthunt rss failure #10688 (#10690)

* 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:
Felix Hsu
2022-09-03 23:47:31 +08:00
committed by GitHub
parent 85eab6cdec
commit a5d0eaeafa
+8 -5
View File
@@ -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'), {