diff --git a/themes/hexo/index.js b/themes/hexo/index.js
index 46660580..fa467a0f 100644
--- a/themes/hexo/index.js
+++ b/themes/hexo/index.js
@@ -223,7 +223,22 @@ const LayoutArchive = (props) => {
*/
const LayoutSlug = props => {
const { post, lock, validPassword } = props
-
+ const router = useRouter()
+ useEffect(() => {
+ // 404
+ if (!post) {
+ setTimeout(() => {
+ if (isBrowser) {
+ const article = document.getElementById('notion-article')
+ if (!article) {
+ router.push('/404').then(() => {
+ console.warn('找不到页面', router.asPath)
+ })
+ }
+ }
+ }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
+ }
+ }, [post])
return (
<>
diff --git a/themes/landing/index.js b/themes/landing/index.js
index cee99448..8944f522 100644
--- a/themes/landing/index.js
+++ b/themes/landing/index.js
@@ -22,6 +22,7 @@ import { isBrowser } from '@/lib/utils'
import { siteConfig } from '@/lib/config'
import { Pricing } from './components/Pricing'
import { LAYOUT_MAPPINGS } from '@/blog.config'
+import { useEffect } from 'react'
/**
* 布局框架
@@ -72,8 +73,26 @@ const LayoutIndex = (props) => {
* @returns
*/
const LayoutSlug = (props) => {
+ const { post } = props
+
// 如果 是 /article/[slug] 的文章路径则进行重定向到另一个域名
const router = useRouter()
+ useEffect(() => {
+ // 404
+ if (!post) {
+ setTimeout(() => {
+ if (isBrowser) {
+ const article = document.getElementById('notion-article')
+ if (!article) {
+ router.push('/404').then(() => {
+ console.warn('找不到页面', router.asPath)
+ })
+ }
+ }
+ }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
+ }
+ }, [post])
+
if (JSON.parse(siteConfig('LANDING_POST_REDIRECT_ENABLE', null, CONFIG)) && isBrowser && router.route === '/[prefix]/[slug]') {
const redirectUrl = siteConfig('LANDING_POST_REDIRECT_URL', null, CONFIG) + router.asPath.replace('?theme=landing', '')
router.push(redirectUrl)
diff --git a/themes/matery/index.js b/themes/matery/index.js
index 81bcc469..b9cd8add 100644
--- a/themes/matery/index.js
+++ b/themes/matery/index.js
@@ -31,6 +31,7 @@ import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
import { siteConfig } from '@/lib/config'
import { LAYOUT_MAPPINGS } from '@/blog.config'
+import { isBrowser } from '@/lib/utils'
/**
* 基础布局
@@ -198,7 +199,22 @@ const LayoutArchive = (props) => {
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const { fullWidth } = useGlobal()
-
+ const router = useRouter()
+ useEffect(() => {
+ // 404
+ if (!post) {
+ setTimeout(() => {
+ if (isBrowser) {
+ const article = document.getElementById('notion-article')
+ if (!article) {
+ router.push('/404').then(() => {
+ console.warn('找不到页面', router.asPath)
+ })
+ }
+ }
+ }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
+ }
+ }, [post])
return (<>
diff --git a/themes/medium/index.js b/themes/medium/index.js
index 608e498c..62170f8e 100644
--- a/themes/medium/index.js
+++ b/themes/medium/index.js
@@ -156,6 +156,23 @@ const LayoutSlug = props => {
)
+ const router = useRouter()
+ useEffect(() => {
+ // 404
+ if (!post) {
+ setTimeout(() => {
+ if (isBrowser) {
+ const article = document.getElementById('notion-article')
+ if (!article) {
+ router.push('/404').then(() => {
+ console.warn('找不到页面', router.asPath)
+ })
+ }
+ }
+ }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
+ }
+ }, [post])
+
return (
{/* 文章锁 */}
diff --git a/themes/nav/index.js b/themes/nav/index.js
index 3defaabf..a793e3e2 100755
--- a/themes/nav/index.js
+++ b/themes/nav/index.js
@@ -35,6 +35,8 @@ import Live2D from '@/components/Live2D'
import BlogArchiveItem from './components/BlogArchiveItem'
import NotionIcon from '@/components/NotionIcon'
import { LAYOUT_MAPPINGS } from '@/blog.config'
+import { useRouter } from 'next/router'
+import { isBrowser } from '@/lib/utils'
const WWAds = dynamic(() => import('@/components/WWAds'), { ssr: false })
@@ -215,6 +217,22 @@ const LayoutPostList = props => {
*/
const LayoutSlug = (props) => {
const { post, lock, validPassword } = props
+ const router = useRouter()
+ useEffect(() => {
+ // 404
+ if (!post) {
+ setTimeout(() => {
+ if (isBrowser) {
+ const article = document.getElementById('notion-article')
+ if (!article) {
+ router.push('/404').then(() => {
+ console.warn('找不到页面', router.asPath)
+ })
+ }
+ }
+ }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
+ }
+ }, [post])
return (
<>
{/* 文章锁 */}
diff --git a/themes/next/index.js b/themes/next/index.js
index bc0c5f83..7e327774 100644
--- a/themes/next/index.js
+++ b/themes/next/index.js
@@ -277,6 +277,23 @@ const LayoutArchive = (props) => {
*/
const LayoutSlug = (props) => {
const { post, lock, validPassword } = props
+
+ const router = useRouter()
+ useEffect(() => {
+ // 404
+ if (!post) {
+ setTimeout(() => {
+ if (isBrowser) {
+ const article = document.getElementById('notion-article')
+ if (!article) {
+ router.push('/404').then(() => {
+ console.warn('找不到页面', router.asPath)
+ })
+ }
+ }
+ }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
+ }
+ }, [post])
return (
<>
diff --git a/themes/nobelium/index.js b/themes/nobelium/index.js
index cdeb8a3e..b7cc2b08 100644
--- a/themes/nobelium/index.js
+++ b/themes/nobelium/index.js
@@ -25,6 +25,7 @@ import replaceSearchResult from '@/components/Mark'
import AlgoliaSearchModal from '@/components/AlgoliaSearchModal'
import { siteConfig } from '@/lib/config'
import { LAYOUT_MAPPINGS } from '@/blog.config'
+import { useRouter } from 'next/router'
// 主题全局状态
const ThemeGlobalNobelium = createContext()
@@ -199,7 +200,22 @@ const LayoutArchive = props => {
*/
const LayoutSlug = props => {
const { post, lock, validPassword } = props
-
+ const router = useRouter()
+ useEffect(() => {
+ // 404
+ if (!post) {
+ setTimeout(() => {
+ if (isBrowser) {
+ const article = document.getElementById('notion-article')
+ if (!article) {
+ router.push('/404').then(() => {
+ console.warn('找不到页面', router.asPath)
+ })
+ }
+ }
+ }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
+ }
+ }, [post])
return (
<>
diff --git a/themes/plog/index.js b/themes/plog/index.js
index 36e30a56..d4b0836a 100644
--- a/themes/plog/index.js
+++ b/themes/plog/index.js
@@ -165,7 +165,22 @@ const LayoutArchive = props => {
*/
const LayoutSlug = props => {
const { post, lock, validPassword } = props
-
+ const router = useRouter()
+ useEffect(() => {
+ // 404
+ if (!post) {
+ setTimeout(() => {
+ if (isBrowser) {
+ const article = document.getElementById('notion-article')
+ if (!article) {
+ router.push('/404').then(() => {
+ console.warn('找不到页面', router.asPath)
+ })
+ }
+ }
+ }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
+ }
+ }, [post])
return (
<>
diff --git a/themes/simple/index.js b/themes/simple/index.js
index 62cdad60..b7598819 100644
--- a/themes/simple/index.js
+++ b/themes/simple/index.js
@@ -12,6 +12,7 @@ import dynamic from 'next/dynamic'
import NotionPage from '@/components/NotionPage'
import AlgoliaSearchModal from '@/components/AlgoliaSearchModal'
import { LAYOUT_MAPPINGS } from '@/blog.config'
+import { useRouter } from 'next/router'
// 主题组件
const BlogListScroll = dynamic(() => import('./components/BlogListScroll'), { ssr: false });
@@ -217,6 +218,23 @@ const LayoutSlug = props => {
* @returns
*/
const Layout404 = (props) => {
+ const { post } = props
+ const router = useRouter()
+ useEffect(() => {
+ // 404
+ if (!post) {
+ setTimeout(() => {
+ if (isBrowser) {
+ const article = document.getElementById('notion-article')
+ if (!article) {
+ router.push('/404').then(() => {
+ console.warn('找不到页面', router.asPath)
+ })
+ }
+ }
+ }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
+ }
+ }, [post])
return <>
404 Not found.
>