mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-01 23:16:51 +00:00
feature: 新增数字分页插件
This commit is contained in:
@@ -16,12 +16,12 @@ export default function Custom404 () {
|
||||
// 延时3秒如果加载失败就返回首页
|
||||
setTimeout(() => {
|
||||
if (window) {
|
||||
const article = document.getElementById('article-wrapper')
|
||||
const article = document.getElementById('container')
|
||||
if (!article) {
|
||||
router.push('/')
|
||||
}
|
||||
}
|
||||
}, 3000)
|
||||
}, 30000000)
|
||||
})
|
||||
|
||||
return <BaseLayout meta={{ title: `${BLOG.title} | 页面找不到啦` }}>
|
||||
|
||||
@@ -4,6 +4,7 @@ import BaseLayout from '@/layouts/BaseLayout'
|
||||
import BlogPostListScroll from '@/components/BlogPostListScroll'
|
||||
import { getNotionPageData } from '@/lib/notion/getNotionData'
|
||||
import Header from '@/components/Header'
|
||||
import BlogPostListPage from '@/components/BlogPostListPage'
|
||||
|
||||
export async function getStaticProps () {
|
||||
const from = 'index'
|
||||
@@ -37,7 +38,11 @@ const Index = ({ allPosts, tags, meta, categories }) => {
|
||||
totalPosts={allPosts}
|
||||
categories={categories}
|
||||
>
|
||||
<BlogPostListScroll posts={allPosts} tags={tags} />
|
||||
{BLOG.postListStyle !== 'page'
|
||||
? (<BlogPostListScroll posts={allPosts} tags={tags} />)
|
||||
: (<BlogPostListPage posts={allPosts} tags={tags} />)
|
||||
}
|
||||
|
||||
</BaseLayout>
|
||||
)
|
||||
}
|
||||
|
||||
65
pages/page/[page].js
Normal file
65
pages/page/[page].js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { getAllCategories, getAllPosts, getAllTags } from '@/lib/notion'
|
||||
import BLOG from '@/blog.config'
|
||||
import BaseLayout from '@/layouts/BaseLayout'
|
||||
import { getNotionPageData } from '@/lib/notion/getNotionData'
|
||||
import Header from '@/components/Header'
|
||||
import Custom404 from '../404'
|
||||
import BlogPostListPage from '@/components/BlogPostListPage'
|
||||
|
||||
const Page = ({ page, allPosts, tags, meta, categories }) => {
|
||||
if (!meta || BLOG.postListStyle !== 'page') {
|
||||
return <Custom404/>
|
||||
}
|
||||
|
||||
return (
|
||||
<BaseLayout
|
||||
headerSlot={BLOG.home.showHomeBanner && <Header />}
|
||||
meta={meta}
|
||||
tags={tags}
|
||||
totalPosts={allPosts}
|
||||
categories={categories}
|
||||
>
|
||||
<BlogPostListPage page={page} posts={allPosts} tags={tags} />
|
||||
</BaseLayout>
|
||||
)
|
||||
}
|
||||
|
||||
export async function getStaticPaths () {
|
||||
const from = 'page'
|
||||
const notionPageData = await getNotionPageData({ from })
|
||||
const allPosts = await getAllPosts({ notionPageData, from })
|
||||
const totalPages = Math.ceil(allPosts / BLOG.postsPerPage)
|
||||
return {
|
||||
// remove first page, we 're not gonna handle that.
|
||||
paths: Array.from({ length: totalPages - 1 }, (_, i) => ({
|
||||
params: { page: '' + (i + 2) }
|
||||
})),
|
||||
fallback: true
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStaticProps ({ params: { page } }) {
|
||||
const from = 'page'
|
||||
const notionPageData = await getNotionPageData({ from })
|
||||
const allPosts = await getAllPosts({ notionPageData, from })
|
||||
const categories = await getAllCategories(allPosts)
|
||||
const tagOptions = notionPageData.tagOptions
|
||||
const tags = await getAllTags({ allPosts, tagOptions })
|
||||
const meta = {
|
||||
title: `${BLOG.title}`,
|
||||
description: BLOG.description,
|
||||
type: 'website'
|
||||
}
|
||||
return {
|
||||
props: {
|
||||
page,
|
||||
allPosts,
|
||||
tags,
|
||||
categories,
|
||||
meta
|
||||
},
|
||||
revalidate: 1
|
||||
}
|
||||
}
|
||||
|
||||
export default Page
|
||||
Reference in New Issue
Block a user