Skip to content

fix: parse Product Hunt data from RSS feed#136

Open
iilw wants to merge 1 commit into
imsyy:masterfrom
iilw:master
Open

fix: parse Product Hunt data from RSS feed#136
iilw wants to merge 1 commit into
imsyy:masterfrom
iilw:master

Conversation

@iilw
Copy link
Copy Markdown

@iilw iilw commented Mar 27, 2026

改成用 /feed

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Product Hunt route to fetch data from the RSS feed instead of scraping the HTML, utilizing a new parseRSS utility. The reviewer suggested improving the robustness of the mapFeedItemToStory function by validating the date parsing to avoid NaN values and recommended removing the export keyword to encapsulate the helper function within the module.

Comment thread src/routes/producthunt.ts
Comment on lines +50 to +61
export const mapFeedItemToStory = (item: ProductHuntFeedItem): ListItem | null => {
if (!item.title || !item.link) return null;

return {
id: item.guid ?? item.link,
title: item.title,
hot: undefined,
timestamp: item.pubDate ? Date.parse(item.pubDate) : undefined,
url: item.link,
mobileUrl: item.link,
};
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

I have a couple of suggestions for the mapFeedItemToStory function:

  1. Robustness: Date.parse() can return NaN for invalid date strings. This can cause issues downstream, for example when creating a Date object from the timestamp. It's better to check for NaN and return undefined for the timestamp to avoid unexpected behavior.
  2. Encapsulation: Since this function is only used within this file, the export keyword can be removed to make it a private helper function for this module.

Here's a suggested implementation incorporating these points:

Suggested change
export const mapFeedItemToStory = (item: ProductHuntFeedItem): ListItem | null => {
if (!item.title || !item.link) return null;
return {
id: item.guid ?? item.link,
title: item.title,
hot: undefined,
timestamp: item.pubDate ? Date.parse(item.pubDate) : undefined,
url: item.link,
mobileUrl: item.link,
};
};
const mapFeedItemToStory = (item: ProductHuntFeedItem): ListItem | null => {
if (!item.title || !item.link) return null;
const timestamp = item.pubDate ? Date.parse(item.pubDate) : undefined;
return {
id: item.guid ?? item.link,
title: item.title,
hot: undefined,
timestamp: timestamp && !isNaN(timestamp) ? timestamp : undefined,
url: item.link,
mobileUrl: item.link,
};
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant