伪静态&刷新缓存时间

This commit is contained in:
tangly1024
2022-12-07 12:52:58 +08:00
parent ac65dbc95c
commit 928585cbf2
14 changed files with 52 additions and 39 deletions

View File

@@ -95,8 +95,10 @@ export async function getStaticPaths() {
}
export async function getStaticProps({ params: { slug } }) {
// slug 是个数组
const fullSlug = slug.join('/')
let fullSlug = slug.join('/')
if (BLOG.PSEUDO_STATIC) {
fullSlug += '.html'
}
const from = `slug-props-${fullSlug}`
const props = await getGlobalNotionData({ from })
props.post = props.allPages.find((p) => {
@@ -106,13 +108,13 @@ export async function getStaticProps({ params: { slug } }) {
if (!props.post) {
const pageId = slug.slice(-1)[0]
if (pageId.length < 32) {
return { props, revalidate: 1 }
return { props, revalidate: BLOG.NEXT_REVALIDATE_SECOND }
}
const post = await getNotion(pageId)
if (post) {
props.post = post
} else {
return { props, revalidate: 1 }
return { props, revalidate: BLOG.NEXT_REVALIDATE_SECOND }
}
} else {
props.post.blockMap = await getPostBlocks(props.post.id, 'slug')
@@ -130,7 +132,7 @@ export async function getStaticProps({ params: { slug } }) {
delete props.allPages
return {
props,
revalidate: 1
revalidate: BLOG.NEXT_REVALIDATE_SECOND
}
}