站点信息读取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

@@ -2,40 +2,31 @@ import { useGlobal } from '@/lib/global'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import * as ThemeMap from '@/themes'
const Tag = (props) => {
const Tag = props => {
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutTag {...props} />
const { locale } = useGlobal()
const { tag, siteInfo, posts } = props
if (!posts) {
return <ThemeComponents.Layout404 {...props}/>
}
const meta = {
title: `${tag} | ${locale.COMMON.TAGS} | ${siteInfo?.title}`,
description: siteInfo?.description,
type: 'website'
}
return <ThemeComponents.LayoutTag {...props} meta={meta}/>
}
export async function getStaticProps ({ params }) {
const tag = params.tag
const from = 'tag-props'
const {
allPosts,
categories,
tags,
postCount,
latestPosts,
customNav
} = await getGlobalNotionData({
from,
includePage: false,
tagsCount: 0
})
const filteredPosts = allPosts.filter(
post => post && post.tags && post.tags.includes(tag)
)
export async function getStaticProps ({ params: { tag } }) {
const props = await getGlobalNotionData({ from: 'tag-props', includePage: false, tagsCount: 0 })
const { allPosts } = props
props.posts = allPosts.filter(post => post && post.tags && post.tags.includes(tag))
props.tag = tag
return {
props: {
tags,
posts: filteredPosts,
tag,
categories,
postCount,
latestPosts,
customNav
},
props,
revalidate: 1
}
}

View File

@@ -3,24 +3,24 @@ import React from 'react'
import { useGlobal } from '@/lib/global'
import * as ThemeMap from '@/themes'
const TagIndex = (props) => {
const TagIndex = props => {
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutTagIndex {...props} />
const { locale } = useGlobal()
const { siteInfo } = props
const meta = {
title: `${locale.COMMON.TAGS} | ${siteInfo.title}`,
description: siteInfo.description,
type: 'website'
}
return <ThemeComponents.LayoutTagIndex {...props} meta={meta} />
}
export async function getStaticProps () {
const from = 'tag-index-props'
const { categories, tags, postCount, latestPosts, customNav } = await getGlobalNotionData({ from, tagsCount: 0 })
const props = await getGlobalNotionData({ from, tagsCount: 0 })
return {
props: {
tags,
categories,
postCount,
latestPosts,
customNav
},
props,
revalidate: 1
}
}