diff --git a/lib/routes/producthunt/templates/descImg.art b/lib/routes/producthunt/templates/descImg.art
deleted file mode 100644
index f66fdd4f6..000000000
--- a/lib/routes/producthunt/templates/descImg.art
+++ /dev/null
@@ -1,5 +0,0 @@
-
-{{ each descData.structuredData.screenshot }}
-
-{{ /each }}
-
diff --git a/lib/routes/producthunt/templates/description.art b/lib/routes/producthunt/templates/description.art
new file mode 100644
index 000000000..8139b84c8
--- /dev/null
+++ b/lib/routes/producthunt/templates/description.art
@@ -0,0 +1,19 @@
+{{ if headerImage }}
+ 
+{{ /if }}
+
+{{ if description }}
+
{{ description }}
+{{ /if }}
+
+{{ if media }}
+ {{ each media m }}
+ {{ if m.mediaType === 'image' }}
+ 
+ {{ else if m.mediaType === 'video' }}
+ {{ if m.metadata.platform === 'youtube' }}
+
+ {{ /if }}
+ {{ /if }}
+ {{ /each }}
+{{ /if }}
diff --git a/lib/routes/producthunt/today.ts b/lib/routes/producthunt/today.ts
index e33fd0fa9..02d59d972 100644
--- a/lib/routes/producthunt/today.ts
+++ b/lib/routes/producthunt/today.ts
@@ -3,7 +3,7 @@ import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);
import cache from '@/utils/cache';
-import got from '@/utils/got';
+import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
@@ -13,7 +13,6 @@ export const route: Route = {
path: '/today',
categories: ['other'],
example: '/producthunt/today',
- parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
@@ -34,33 +33,61 @@ export const route: Route = {
};
async function handler() {
- const response = await got('https://www.producthunt.com/');
+ const response = await ofetch('https://www.producthunt.com/');
- const data = JSON.parse(load(response.data)('#__NEXT_DATA__').html());
+ const $ = load(response);
+ const match = $('script:contains("ApolloSSRDataTransport")')
+ .text()
+ .match(/"events":(\[.+\])\}\)/)?.[1]
+ .replaceAll('undefined', 'null');
- const list = Object.values(data.props.apolloState)
- .filter((o) => o.__typename === 'Post')
- // only includes new post, not product
- .filter((o) => Object.hasOwn(o, 'redirectToProduct') && o.redirectToProduct === null);
+ const data = JSON.parse(match);
+ const todayList = data.find((event) => event.type === 'data' && event.result.data.homefeed).result.data.homefeed.edges.find((edge) => edge.node.id === 'FEATURED-0').node;
+ // 0: Top Products Launching Today
+ // 1: Yesterday's Top Products
+ // 2: Last Week's Top Products
+ // 3: Last Month's Top Products
+
+ const list = todayList.items
+ .filter((i) => i.__typename === 'Post')
+ .map((item) => ({
+ title: item.name,
+ link: `https://www.producthunt.com/posts/${item.slug}`,
+ slug: item.slug,
+ description: item.tagline,
+ pubDate: parseDate(item.createdAt),
+ image: `https://ph-files.imgix.net/${item.thumbnailImageUuid}`,
+ categories: item.topics.edges.map((topic) => topic.node.name),
+ }));
const items = await Promise.all(
list.map((item) =>
- cache.tryGet(item.slug, async () => {
- const detailresponse = await got(`https://www.producthunt.com/posts/${item.slug}`);
+ cache.tryGet(item.link, async () => {
+ const response = await ofetch('https://www.producthunt.com/frontend/graphql', {
+ method: 'POST',
+ body: {
+ operationName: 'PostPage',
+ variables: {
+ slug: item.slug,
+ },
+ extensions: {
+ persistedQuery: {
+ version: 1,
+ sha256Hash: '3d56ad0687ad82922d71fca238e5081853609dd7b16207a5aa042dee884edaea',
+ },
+ },
+ },
+ });
+ const post = response.data.post;
- const data = JSON.parse(load(detailresponse.data)('#__NEXT_DATA__').html());
- const descData = data.props.apolloState[`Post${item.id}`];
+ item.author = post.user.name;
+ item.description = art(path.join(__dirname, 'templates/description.art'), {
+ headerImage: post.headerImage?.uuid,
+ description: post.description,
+ media: post.media,
+ });
- return {
- title: `${item.slug} - ${item.tagline}`,
- description:
- descData.description +
- art(path.join(__dirname, 'templates/descImg.art'), {
- descData,
- }),
- link: `https://www.producthunt.com/posts/${item.slug}`,
- pubDate: parseDate(descData.createdAt),
- };
+ return item;
})
)
);