站点信息读取Notion数据

This commit is contained in:
tangly1024
2022-03-30 15:34:25 +08:00
parent 914e9a108f
commit 53c004843e
61 changed files with 322 additions and 463 deletions

View File

@@ -6,33 +6,29 @@ import * as ThemeMap from '@/themes'
export default function Category (props) {
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutCategory {...props} />
const { siteInfo, posts } = props
const { locale } = useGlobal()
if (!posts) {
return <ThemeComponents.Layout404 {...props}/>
}
const meta = {
title: `${props.category} | ${locale.COMMON.CATEGORY} | ${siteInfo?.title || ''}`,
description: siteInfo?.description,
type: 'website'
}
return <ThemeComponents.LayoutCategory {...props} meta={meta} />
}
export async function getStaticProps ({ params }) {
export async function getStaticProps ({ params: { category } }) {
const from = 'category-props'
const category = params.category
const {
allPosts,
categories,
tags,
postCount,
latestPosts,
customNav
} = await getGlobalNotionData({ from })
const filteredPosts = allPosts.filter(
let props = await getGlobalNotionData({ from })
const posts = props.allPosts.filter(
post => post && post.category && post.category.includes(category)
)
props = { ...props, posts, category }
return {
props: {
tags,
posts: filteredPosts,
category,
categories,
postCount,
latestPosts,
customNav
},
props,
revalidate: 1
}
}

View File

@@ -6,22 +6,20 @@ import * as ThemeMap from '@/themes'
export default function Category (props) {
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutCategoryIndex {...props}/>
const { locale } = useGlobal()
const { siteInfo } = props
const meta = {
title: `${locale.COMMON.CATEGORY} | ${siteInfo.title}`,
description: siteInfo.description,
type: 'website'
}
return <ThemeComponents.LayoutCategoryIndex {...props} meta={meta}/>
}
export async function getStaticProps () {
const from = 'category-index-props'
const { allPosts, categories, tags, postCount, latestPosts, customNav } = await getGlobalNotionData({ from, categoryCount: 0 })
const props = await getGlobalNotionData({ from: 'category-index-props', categoryCount: 0 })
return {
props: {
tags,
allPosts,
categories,
postCount,
latestPosts,
customNav
},
props,
revalidate: 1
}
}