diff --git a/components/PaginationNumber.js b/components/PaginationNumber.js
new file mode 100644
index 00000000..d7f36f59
--- /dev/null
+++ b/components/PaginationNumber.js
@@ -0,0 +1,95 @@
+import BLOG from '@/blog.config'
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
+import { faAngleLeft, faAngleRight } from '@fortawesome/free-solid-svg-icons'
+
+/**
+ * 数字翻页插件
+ * @param page 当前页码
+ * @param showNext 是否有下一页
+ * @returns {JSX.Element}
+ * @constructor
+ */
+const PaginationNumber = ({ page, showNext, totalPage }) => {
+ const router = useRouter()
+ const currentPage = +page
+ const pages = generatePages(page, currentPage, totalPage)
+
+ return (
+
+
+ {/* 上一页 */}
+
+
+
+
+
+
+ {pages}
+
+ {/* 下一页 */}
+
+
+
+
+
+
+ )
+}
+
+function getPageElement (page, currentPage) {
+ console.log(page, currentPage)
+ return
+
+ {page}
+
+
+}
+function generatePages (page, currentPage, totalPage) {
+ const pages = []
+ const startPage = 1 // 分组开始页码
+ const groupCount = 5 // 页码分组
+ if (totalPage <= 10) {
+ for (let i = 1; i <= totalPage; i++) {
+ pages.push(getPageElement(i, page))
+ }
+ } else {
+ pages.push(getPageElement(1, page))
+
+ let pageLength = 0
+ if (groupCount + startPage > totalPage) {
+ pageLength = totalPage
+ } else {
+ pageLength = groupCount + startPage
+ }
+
+ if (currentPage >= groupCount) {
+ pages.push(
...
)
+ }
+
+ for (let i = startPage; i < pageLength; i++) {
+ if (i <= totalPage - 1 && i > 1) {
+ pages.push(getPageElement(i, page))
+ }
+ }
+
+ if (totalPage - startPage >= groupCount + 1) {
+ pages.push(
...
)
+ }
+
+ pages.push(getPageElement(totalPage, page))
+ }
+ return pages
+}
+export default PaginationNumber
diff --git a/components/Pagination.js b/components/PaginationSimple.js
similarity index 92%
rename from components/Pagination.js
rename to components/PaginationSimple.js
index 6753987e..5a2b7064 100644
--- a/components/Pagination.js
+++ b/components/PaginationSimple.js
@@ -4,13 +4,13 @@ import { useRouter } from 'next/router'
import { useGlobal } from '@/lib/global'
/**
- * 翻页插件
+ * 简易翻页插件
* @param page 当前页码
* @param showNext 是否有下一页
* @returns {JSX.Element}
* @constructor
*/
-const Pagination = ({ page, showNext }) => {
+const PaginationSimple = ({ page, showNext }) => {
const { locale } = useGlobal()
const router = useRouter()
const currentPage = +page
@@ -39,4 +39,4 @@ const Pagination = ({ page, showNext }) => {
)
}
-export default Pagination
+export default PaginationSimple
diff --git a/pages/404.js b/pages/404.js
index efad0005..df0f6ce7 100644
--- a/pages/404.js
+++ b/pages/404.js
@@ -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
diff --git a/pages/index.js b/pages/index.js
index 0780e76a..8aef2625 100644
--- a/pages/index.js
+++ b/pages/index.js
@@ -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}
>
-
+ {BLOG.postListStyle !== 'page'
+ ? ( )
+ : ( )
+ }
+
)
}
diff --git a/pages/page/[page].js b/pages/page/[page].js
new file mode 100644
index 00000000..e7a86cb8
--- /dev/null
+++ b/pages/page/[page].js
@@ -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
+ }
+
+ return (
+
}
+ meta={meta}
+ tags={tags}
+ totalPosts={allPosts}
+ categories={categories}
+ >
+
+
+ )
+}
+
+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