优化增量静态及404处理

This commit is contained in:
tangly1024
2022-04-26 22:20:02 +08:00
parent 5a884f9a73
commit d0edae963b
10 changed files with 71 additions and 51 deletions

View File

@@ -3,9 +3,9 @@ import { getPostBlocks } from '@/lib/notion'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import { useGlobal } from '@/lib/global'
import * as ThemeMap from '@/themes'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/router'
import React from 'react'
import { idToUuid } from 'notion-utils'
import { useRouter } from 'next/router'
/**
* 根据notion的slug访问页面
@@ -13,32 +13,33 @@ import { idToUuid } from 'notion-utils'
* @returns
*/
const Slug = props => {
const { theme } = useGlobal()
const { theme, changeLoadingState } = useGlobal()
const ThemeComponents = ThemeMap[theme]
const { post } = props
if (!post) {
changeLoadingState(true)
const router = useRouter()
useEffect(() => {
setTimeout(() => {
if (window) {
const article = typeof document !== 'undefined' && document.getElementById('container')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)
})
}
setTimeout(() => {
if (typeof document !== 'undefined') {
const article = document.getElementById('container')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)
})
}
}, 3000)
})
}
}, 5000)
const meta = { title: `${props?.siteInfo?.title || BLOG.TITLE} | loading` }
return <ThemeComponents.LayoutSlug {...props} showArticleInfo={true} meta={meta} />
}
changeLoadingState(false)
// 文章锁🔐
const [lock, setLock] = useState(post.password && post.password !== '')
useEffect(() => {
if (post.password && post.password !== '') {
const [lock, setLock] = React.useState(post?.password && post?.password !== '')
React.useEffect(() => {
if (post?.password && post?.password !== '') {
setLock(true)
} else {
setLock(false)
@@ -46,9 +47,9 @@ const Slug = props => {
}, [post])
/**
* 验证文章密码
* @param {*} result
*/
* 验证文章密码
* @param {*} result
*/
const validPassword = result => {
if (result) {
setLock(false)
@@ -59,13 +60,13 @@ const Slug = props => {
const { siteInfo } = props
const meta = {
title: `${props.post.title} | ${siteInfo.title}`,
description: props.post.summary,
title: `${post?.title} | ${siteInfo?.title}`,
description: post?.summary,
type: 'article',
slug: 'article/' + props.post.slug,
image: props.post.page_cover,
category: props.post.category?.[0],
tags: props.post.tags
slug: 'article/' + post?.slug,
image: post?.page_cover,
category: post?.category?.[0],
tags: post?.tags
}
return (