diff --git a/frontend/apps/service-site/src/features/posts/components/PostListPage/PostListPage.tsx b/frontend/apps/service-site/src/features/posts/components/PostListPage/PostListPage.tsx index ac69fc90a..7b03490c9 100644 --- a/frontend/apps/service-site/src/features/posts/components/PostListPage/PostListPage.tsx +++ b/frontend/apps/service-site/src/features/posts/components/PostListPage/PostListPage.tsx @@ -1,10 +1,10 @@ import { type Lang, getTranslation } from '@/features/i18n' import { MDXContent } from '@/libs/contentlayer' import type { Post } from 'contentlayer/generated' -import { compareDesc, format, parseISO } from 'date-fns' +import { format, parseISO } from 'date-fns' import Link from 'next/link' import type { FC } from 'react' -import { filterPostsByLang } from '../../utils' +import { filterPostsByLang, sortPostsByDate } from '../../utils' function PostCard(post: Post) { return ( @@ -28,9 +28,7 @@ export const PostListPage: FC = ({ lang }) => { const { t } = getTranslation(lang) const posts = filterPostsByLang(lang) - const sortedPosts = posts.sort((a, b) => - compareDesc(new Date(a.date), new Date(b.date)), - ) + const sortedPosts = sortPostsByDate(posts) return (
diff --git a/frontend/apps/service-site/src/features/posts/utils/index.ts b/frontend/apps/service-site/src/features/posts/utils/index.ts index 824f2cbb9..205b31b29 100644 --- a/frontend/apps/service-site/src/features/posts/utils/index.ts +++ b/frontend/apps/service-site/src/features/posts/utils/index.ts @@ -1,2 +1,3 @@ export * from './filterPostsByLang' export * from './findPostByLangAndSlug' +export * from './sortPostsByDate' diff --git a/frontend/apps/service-site/src/features/posts/utils/sortPostsByDate.ts b/frontend/apps/service-site/src/features/posts/utils/sortPostsByDate.ts new file mode 100644 index 000000000..6df2f4ed9 --- /dev/null +++ b/frontend/apps/service-site/src/features/posts/utils/sortPostsByDate.ts @@ -0,0 +1,6 @@ +import type { Post } from 'contentlayer/generated' +import { compareDesc } from 'date-fns' + +export function sortPostsByDate(posts: Post[]) { + return posts.sort((a, b) => compareDesc(new Date(a.date), new Date(b.date))) +} diff --git a/frontend/apps/service-site/src/features/top/components/TopPage/TopPage.tsx b/frontend/apps/service-site/src/features/top/components/TopPage/TopPage.tsx index 412fc8012..887127fb9 100644 --- a/frontend/apps/service-site/src/features/top/components/TopPage/TopPage.tsx +++ b/frontend/apps/service-site/src/features/top/components/TopPage/TopPage.tsx @@ -1,7 +1,6 @@ import { TopCards } from '@/components' import type { Lang } from '@/features/i18n' -import { filterPostsByLang } from '@/features/posts' -import { compareDesc } from 'date-fns' +import { filterPostsByLang, sortPostsByDate } from '@/features/posts' import type { FC } from 'react' type Props = { @@ -10,9 +9,7 @@ type Props = { export const TopPage: FC = ({ lang }) => { const posts = filterPostsByLang(lang) - const sortedPosts = posts.sort((a, b) => - compareDesc(new Date(a.date), new Date(b.date)), - ) + const sortedPosts = sortPostsByDate(posts) return }