|
import { getGlobalData } from '@/lib/notion/getNotionData' |
|
import React from 'react' |
|
import BLOG from '@/blog.config' |
|
import { useRouter } from 'next/router' |
|
import { getLayoutByTheme } from '@/themes/theme' |
|
import { siteConfig } from '@/lib/config' |
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function Category(props) { |
|
|
|
const Layout = getLayoutByTheme({ theme: siteConfig('THEME'), router: useRouter() }) |
|
|
|
return <Layout {...props} /> |
|
} |
|
|
|
export async function getStaticProps({ params: { category } }) { |
|
const from = 'category-props' |
|
let props = await getGlobalData({ from }) |
|
|
|
|
|
props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published') |
|
|
|
props.posts = props.posts.filter(post => post && post.category && post.category.includes(category)) |
|
|
|
props.postCount = props.posts.length |
|
|
|
if (BLOG.POST_LIST_STYLE === 'scroll') { |
|
|
|
} else if (BLOG.POST_LIST_STYLE === 'page') { |
|
props.posts = props.posts?.slice(0, BLOG.POSTS_PER_PAGE) |
|
} |
|
|
|
delete props.allPages |
|
|
|
props = { ...props, category } |
|
|
|
return { |
|
props, |
|
revalidate: parseInt(BLOG.NEXT_REVALIDATE_SECOND) |
|
} |
|
} |
|
|
|
export async function getStaticPaths() { |
|
const from = 'category-paths' |
|
const { categoryOptions } = await getGlobalData({ from }) |
|
return { |
|
paths: Object.keys(categoryOptions).map(category => ({ |
|
params: { category: categoryOptions[category]?.name } |
|
})), |
|
fallback: true |
|
} |
|
} |
|
|