diff --git a/lib/v2/producthunt/today.js b/lib/v2/producthunt/today.js index d96d759afe..0cf40ee0c3 100644 --- a/lib/v2/producthunt/today.js +++ b/lib/v2/producthunt/today.js @@ -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'), {