Skip to content

Conversation

palladius
Copy link
Owner

Not sure if this is safe. It's deleting plenty of stuff

Copy link

🤖 Hi @palladius, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

@palladius
Copy link
Owner Author

this fixes #7
but it doesnt convince me.

@gemini-cli I see there's a JS where a lot of code is removed, do you think its safe to merge?

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

📋 Review Summary

This pull request effectively resolves the 404 errors on talk and article detail pages by standardizing the date format in slugs. The approach is solid and the core logic is sound.

🔍 General Feedback

  • The transition from mocked unit tests to integration tests is a significant improvement and greatly increases confidence in the data-fetching logic.
  • The introduction of a formatDate utility is a good step towards consistency. I've provided a suggestion to make it more robust against timezone-related issues.
  • I've also suggested a small improvement for date parsing to leverage the existing parseDateString utility for better consistency and reliability.

Overall, these are great changes. The author's concern about "deleting plenty of stuff" is understandable given the test file rewrite, but the new tests are much more valuable. Well done!


export const formatDate = (date: Date): string => {
if (!date) return '';
return new Date(date).toISOString().split('T')[0];

Choose a reason for hiding this comment

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

🟢 Using toISOString can lead to off-by-one day errors due to timezone conversions, as it always returns the date in UTC. A safer approach is to construct the date string from the local date components (getFullYear, getMonth, getDate). This ensures that the formatted date matches the local date, regardless of the timezone.

Suggested change
return new Date(date).toISOString().split('T')[0];
const d = new Date(date);
const year = d.getFullYear();
const month = `${d.getMonth() + 1}`.padStart(2, '0');
const day = `${d.getDate()}`.padStart(2, '0');
return `${year}-${month}-${day}`;

@@ -31,7 +31,7 @@ export async function getArticles() {
});
return articles.map((article) => ({
...article,
slug: `${article.publish_date}-${slugify(article.title)}`,
slug: `${formatDate(new Date(article.publish_date))}-${slugify(article.title)}`,

Choose a reason for hiding this comment

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

🟢 For consistency and robustness, it's better to use the existing parseDateString utility to parse the publish_date string. The new Date(dateString) constructor can have inconsistent behavior across different JavaScript environments, whereas parseDateString is guaranteed to handle the YYYY-MM-DD format correctly. You'll also need to import parseDateString from ../../lib/utils.

Suggested change
slug: `${formatDate(new Date(article.publish_date))}-${slugify(article.title)}`,
slug: `${formatDate(parseDateString(article.publish_date))}-${slugify(article.title)}`,

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