-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: migrate from moment.js to date-fns for better performance and bundle size #5019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| import moment from 'moment'; | ||
| import ErrorPage from 'next/error'; | ||
| import HtmlHead from 'next/head'; | ||
| import { useRouter } from 'next/router'; | ||
|
|
@@ -7,6 +6,7 @@ import React from 'react'; | |
| import type { IPosts } from '@/types/post'; | ||
|
|
||
| import BlogContext from '../../context/BlogContext'; | ||
| import { formatDate } from '../../utils/dateHelpers'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Check frontmatter date fields in markdown files
fd -e md -e mdx | xargs rg -n '^date:\s*' -A 0 || trueRepository: asyncapi/website Length of output: 12099 🏁 Script executed: # Find and examine the formatDate implementation
fd -e ts -e tsx -e js -e jsx | xargs rg -l 'formatDate|parseISO' | head -20Repository: asyncapi/website Length of output: 321 🏁 Script executed: # Get context around line 74 in BlogLayout.tsx
fd -e tsx | xargs grep -l 'BlogLayout' | head -1 | xargs sed -n '70,80p'Repository: asyncapi/website Length of output: 543 🏁 Script executed: # Check dateHelpers implementation
fd -e ts -e tsx -e js -e jsx -path '*/utils/*' | xargs grep -l 'formatDate\|parseISO' || trueRepository: asyncapi/website Length of output: 228 🏁 Script executed: # Read dateHelpers.ts implementation
fd -name 'dateHelpers.ts' -o -name 'dateHelpers.js' | xargs catRepository: asyncapi/website Length of output: 290 🏁 Script executed: # Check how blog posts are loaded/parsed
fd -name '*blog*' -type f | xargs rg -l 'getAllPosts\|getBlogPosts\|frontmatter\|gray-matter' | head -5Repository: asyncapi/website Length of output: 290 🏁 Script executed: # Search for blog data loading in pages or API routes
fd -name 'index.tsx' -o -name 'index.ts' | xargs rg -l 'blog\|post' | head -5Repository: asyncapi/website Length of output: 290 🏁 Script executed: # Find and read dateHelpers.ts
find . -name 'dateHelpers.ts' -o -name 'dateHelpers.js' | head -1 | xargs catRepository: asyncapi/website Length of output: 2086 🏁 Script executed: # Search for blog data loading utilities
find . -type f -name '*.ts' -o -name '*.tsx' | xargs grep -l 'getAllPosts\|getBlogPosts' 2>/dev/null | head -5Repository: asyncapi/website Length of output: 234 🏁 Script executed: # Check BlogLayout context around line 74 and 9
find . -name 'BlogLayout.tsx' | xargs catRepository: asyncapi/website Length of output: 3720 🏁 Script executed: # Find where blog posts are loaded/parsed
find . -type f \( -name '*.ts' -o -name '*.tsx' \) | xargs grep -l 'post.date\|getPosts\|getAllPosts' 2>/dev/null | head -10Repository: asyncapi/website Length of output: 410 🏁 Script executed: # Check for blog data transformation/frontmatter parsing
find . -type f \( -name '*.ts' -o -name '*.tsx' \) | xargs grep -l 'frontmatter\|gray-matter\|parseISO' 2>/dev/null | head -10Repository: asyncapi/website Length of output: 188 🏁 Script executed: # Look for the types definition to understand what post.date is
find . -type f -name 'post.ts' -o -name 'post.d.ts' -o -name '*.ts' | xargs grep -l 'interface IPosts\|type IPosts' 2>/dev/null | head -5Repository: asyncapi/website Length of output: 75 🏁 Script executed: # Read the post types definition
cat ./types/post.tsRepository: asyncapi/website Length of output: 621 🏁 Script executed: # Read build-post-list.ts to see date processing
cat ./scripts/build-post-list.tsRepository: asyncapi/website Length of output: 13127 🏁 Script executed: # Check utils/api.ts for date handling
cat ./utils/api.tsRepository: asyncapi/website Length of output: 1359 Add error handling for date parsing in export function formatDate(date: string | Date, formatStr: string): string {
let parsedDate: Date;
try {
parsedDate = typeof date === 'string' ? parseISO(date) : date;
} catch (e) {
parsedDate = new Date(date); // fallback to native Date parsing
}
return isValid(parsedDate) ? format(parsedDate, formatStr) : 'Invalid date';
}Also applies to: 74-74 🤖 Prompt for AI Agents |
||
| import AuthorAvatars from '../AuthorAvatars'; | ||
| import AnnouncementHero from '../campaigns/AnnouncementHero'; | ||
| import Head from '../Head'; | ||
|
|
@@ -71,7 +71,7 @@ export default function BlogLayout({ post, children }: IBlogLayoutProps) { | |
| </span> | ||
| </p> | ||
| <div className='flex text-sm leading-5 text-gray-500'> | ||
| <time dateTime={post.date}>{moment(post.date).format('MMMM D, YYYY')}</time> | ||
| <time dateTime={post.date}>{formatDate(post.date, 'MMMM d, yyyy')}</time> | ||
| <span className='mx-1'>·</span> | ||
| <span>{post.readingTime} min read</span> | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| import moment from 'moment'; | ||
| import Link from 'next/link'; | ||
| import type { Ref } from 'react'; | ||
| import React, { forwardRef } from 'react'; | ||
| import TextTruncate from 'react-text-truncate'; | ||
|
|
||
| import { BlogPostType } from '@/types/components/navigation/BlogPostType'; | ||
| import { formatDate } from '@/utils/dateHelpers'; | ||
| import type { IBlogPost } from '@/types/post'; | ||
|
Comment on lines
1
to
7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import order is failing CI. 🧰 Tools🪛 GitHub Actions: PR testing - if Node project[error] 1-1: Run autofix to sort these imports! 🤖 Prompt for AI Agents |
||
| import { HeadingLevel, HeadingTypeStyle } from '@/types/typography/Heading'; | ||
| import { ParagraphTypeStyle } from '@/types/typography/Paragraph'; | ||
|
|
@@ -129,7 +129,7 @@ const BlogPostItem = ({ post, className = '', id = '' }: BlogPostItemProps, ref: | |
| </span> | ||
| </Heading> | ||
| <Paragraph typeStyle={ParagraphTypeStyle.sm} className='flex'> | ||
| <time dateTime={post.date}>{moment(post.date).format('MMMM D, YYYY')}</time> | ||
| <time dateTime={post.date}>{formatDate(post.date, 'MMMM d, yyyy')}</time> | ||
| <span className='mx-1'>·</span> | ||
| <span>{post.readingTime} min read</span> | ||
| </Paragraph> | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.