Skip to content

Commit

Permalink
date sort is only for news
Browse files Browse the repository at this point in the history
  • Loading branch information
KishiTheMechanic committed Oct 11, 2024
1 parent 2376be9 commit 79da4f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 6 additions & 7 deletions src/app/[locale]/(default)/news/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ArticlePageProps,
getDataForArticlePageByFilename,
getArticleBySlug,
getArticleForIndex,
getArticleForIndex
} from '@/lib/articles'
import NewsMobileHeader from '../NewsMobileHeader'
import ScrollSyncToc from '@/components/articles/ScrollSyncToc'
Expand All @@ -16,13 +16,12 @@ import ArticleIndex from '@/components/articles/ArticleIndex'
import { usePagerData } from '@/hooks/articles/usePagerData'
import ArticlePager from '@/components/articles/ArticlePager'


const { groupDir, generateMetadata, generateStaticParams, getArticlePaths } =
getDataForArticlePageByFilename(__filename)
export { generateMetadata, generateStaticParams }

export default function NewsArticlePage({
params: { locale, slug },
params: { locale, slug }
}: ArticlePageProps) {
unstable_setRequestLocale(locale)
const t = useTranslations()
Expand All @@ -31,20 +30,20 @@ export default function NewsArticlePage({
slug,
['title', 'category', 'thumbnail', 'date', 'content'],
groupDir,
locale,
locale
)

const articlesData = getArticleForIndex(
groupDir,
['title', 'thumbnail', 'date'],
locale,
locale
)

const pagerData = usePagerData({
slug,
groupDir,
locale,
articlePaths: getArticlePaths(),
articlePaths: getArticlePaths()
})

return (
Expand Down Expand Up @@ -89,7 +88,7 @@ export default function NewsArticlePage({
<div
className={cn(
'scrollbar-thumb-rounded-full scrollbar-track-rounded-full overflow-auto scrollbar-thin scrollbar-track-white scrollbar-thumb-zinc-300 dark:scrollbar-track-zinc-950 dark:scrollbar-thumb-zinc-600',
'hidden max-h-[calc(100vh-10rem)] md:sticky md:top-32 md:block',
'hidden max-h-[calc(100vh-10rem)] md:sticky md:top-32 md:block'
)}
>
<ScrollSyncToc rawMarkdownBody={articleData.content as string} />
Expand Down
12 changes: 7 additions & 5 deletions src/lib/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ export const getArticleForIndex = (
): ArticleData[] => {
let slugs: string[][] = getAllArticles(groupDir)

slugs = slugs.sort((a, b) => {
const dateA = new Date(`${a[0]}-${a[1]}-${a[2]}`)
const dateB = new Date(`${b[0]}-${b[1]}-${b[2]}`)
return dateB.getTime() - dateA.getTime()
})
if (groupDir === 'news') {
slugs = slugs.sort((a, b) => {
const dateA = new Date(`${a[0]}-${a[1]}-${a[2]}`)
const dateB = new Date(`${b[0]}-${b[1]}-${b[2]}`)
return dateB.getTime() - dateA.getTime()
})
}

const articles = slugs.map((slug) =>
getArticleBySlug(slug, matterArray, groupDir, locale)
Expand Down

0 comments on commit 79da4f5

Please sign in to comment.