2023-04-25 11:01:25 +00:00
|
|
|
import { ArticleDetails } from '@/components/ArticleDetails'
|
|
|
|
import { ArticleNavLinks } from '@/components/ArticleNavLinks'
|
|
|
|
import { Breadcrumb } from '@/components/Breadcrumb'
|
|
|
|
import { Mdx } from '@/components/Mdx'
|
|
|
|
import { MetaHead } from '@/components/MetaHead'
|
|
|
|
import { Sidebar } from '@/components/Sidebar'
|
|
|
|
import { Article, ArticleLinks, Category, Section, SidebarContentList } from '@/types/content-types'
|
|
|
|
import {
|
|
|
|
getArticle,
|
|
|
|
getArticleSource,
|
|
|
|
getCategory,
|
|
|
|
getLinks,
|
|
|
|
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'
|
|
|
|
|
2023-06-19 18:48:55 +00:00
|
|
|
export type ArticleProps = {
|
|
|
|
type: 'article'
|
2023-04-25 11:01:25 +00:00
|
|
|
sidebar: SidebarContentList
|
|
|
|
section: Section
|
|
|
|
category: Category
|
|
|
|
article: Article
|
|
|
|
links: ArticleLinks
|
|
|
|
mdxSource: MDXRemoteSerializeResult
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function ArticlePage({
|
|
|
|
mdxSource,
|
|
|
|
section,
|
|
|
|
category,
|
|
|
|
article,
|
|
|
|
links,
|
|
|
|
sidebar,
|
2023-06-19 18:48:55 +00:00
|
|
|
}: ArticleProps) {
|
2023-04-25 11:01:25 +00:00
|
|
|
const theme = useTheme()
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<MetaHead title={article.title} description={article.description} hero={article.hero} />
|
|
|
|
<div className="layout">
|
|
|
|
<Sidebar {...sidebar} />
|
|
|
|
<main className={`article ${theme.theme ?? 'light'}`}>
|
|
|
|
<Breadcrumb section={section} category={category} />
|
|
|
|
<h1>{article.title}</h1>
|
|
|
|
<Mdx mdxSource={mdxSource} />
|
|
|
|
<ArticleDetails article={article} />
|
|
|
|
<ArticleNavLinks links={links} />
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getStaticPaths: GetStaticPaths = async () => {
|
|
|
|
const sections = await getSections()
|
2023-06-19 18:48:55 +00:00
|
|
|
const paths: { params: { sectionId: string; childId: string; articleId: string } }[] = []
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
for (const section of sections) {
|
|
|
|
for (const category of section.categories) {
|
2023-06-19 18:48:55 +00:00
|
|
|
if (category.id === 'ucg') continue
|
2023-04-25 11:01:25 +00:00
|
|
|
for (const articleId of category.articleIds) {
|
2023-06-19 18:48:55 +00:00
|
|
|
paths.push({ params: { sectionId: section.id, childId: category.id, articleId } })
|
2023-04-25 11:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { paths, fallback: false }
|
|
|
|
}
|
|
|
|
|
2023-06-19 18:48:55 +00:00
|
|
|
export const getStaticProps: GetStaticProps<ArticleProps> = async (ctx) => {
|
2023-04-25 11:01:25 +00:00
|
|
|
const sectionId = ctx.params?.sectionId?.toString() as string
|
2023-06-19 18:48:55 +00:00
|
|
|
const categoryId = ctx.params?.childId?.toString() as string
|
2023-04-25 11:01:25 +00:00
|
|
|
const articleId = ctx.params?.articleId?.toString()
|
|
|
|
if (!articleId) throw Error()
|
|
|
|
|
|
|
|
const sidebar = await getSidebarContentList({ sectionId, categoryId, articleId })
|
|
|
|
const section = await getSection(sectionId)
|
|
|
|
const category = await getCategory(sectionId, categoryId)
|
|
|
|
const article = await getArticle(articleId)
|
|
|
|
const links = await getLinks(articleId)
|
|
|
|
const mdxSource = await getArticleSource(articleId)
|
|
|
|
|
2023-06-19 18:48:55 +00:00
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
type: 'article',
|
|
|
|
article,
|
|
|
|
section,
|
|
|
|
category,
|
|
|
|
sidebar,
|
|
|
|
links,
|
|
|
|
mdxSource,
|
|
|
|
},
|
|
|
|
}
|
2023-04-25 11:01:25 +00:00
|
|
|
}
|