{category.title}
{mdxSource &&{group.title}
-
{articles.map((article) => (
- {article.title} ))}
-
{ungrouped.map((article) => (
- {article.title} ))}
import { Breadcrumb } from '@/components/Breadcrumb'
import { Mdx } from '@/components/Mdx'
import { MetaHead } from '@/components/MetaHead'
import { Sidebar } from '@/components/Sidebar'
import { Article, Category, Section, SidebarContentList } from '@/types/content-types'
import {
getArticleSource,
getArticles,
getCategory,
getSection,
getSections,
} from '@/utils/content'
import { getSidebarContentList } from '@/utils/getSidebarContentList'
import { GetStaticPaths, GetStaticProps } from 'next'
import { MDXRemoteSerializeResult } from 'next-mdx-remote'
import { useTheme } from 'next-themes'
import Link from 'next/link'
type Props = {
sidebar: SidebarContentList
section: Section
category: Category
articles: Article[]
mdxSource: MDXRemoteSerializeResult | null
}
export default function CategoryListPage({
sidebar,
mdxSource,
articles,
section,
category,
}: Props) {
const theme = useTheme()
const ungrouped: Article[] = []
const groupedArticles = Object.fromEntries(
category.groups.map((group) => [group.id, { group, articles: [] as Article[] }])
)
for (const article of articles) {
if (article.groupId) {
if (groupedArticles[article.groupId]) {
groupedArticles[article.groupId].articles.push(article)
} else {
throw Error(
`Article ${article.id} has groupId ${article.groupId} but no such group exists.`
)
}
} else {
ungrouped.push(article)
}
}
return (
<>