标题处理、标签页分页处理

This commit is contained in:
tangly1024
2021-10-16 15:26:09 +08:00
parent bca507029c
commit 3d70843441
12 changed files with 205 additions and 209 deletions

View File

@@ -7,7 +7,7 @@ import Custom404 from '@/pages/404'
const BlogPost = ({ post, blockMap, emailHash, tags, prev, next }) => {
if (!post) {
return <Custom404/>
return <Custom404 />
}
return (
<ArticleLayout
@@ -22,11 +22,18 @@ const BlogPost = ({ post, blockMap, emailHash, tags, prev, next }) => {
}
export async function getStaticPaths () {
let posts = await getAllPosts()
posts = posts.filter(post => post.status[0] === 'Published')
return {
paths: posts.map(row => `${BLOG.path}/article/${row.slug}`),
fallback: true
if (BLOg.isProd) {
let posts = await getAllPosts()
posts = posts.filter(post => post.status[0] === 'Published')
return {
paths: posts.map(row => `${BLOG.path}/article/${row.slug}`),
fallback: true
}
} else {
return {
paths: [],
fallback: true
}
}
}
@@ -36,7 +43,7 @@ export async function getStaticProps ({ params: { slug } }) {
const post = posts.find(t => t.slug === slug)
if (!post) {
return {
props: { },
props: {},
revalidate: 1
}
}

View File

@@ -1,5 +1,6 @@
import { getAllPosts, getAllTags } from '@/lib/notion'
import IndexLayout from '@/layouts/IndexLayout'
import BLOG from '@/blog.config'
export async function getStaticProps () {
let posts = await getAllPosts()
@@ -7,20 +8,25 @@ export async function getStaticProps () {
post => post.status[0] === 'Published' && post.type[0] === 'Post'
)
const tags = await getAllTags(posts)
const meta = {
title: `${BLOG.title} | 首页`,
description: BLOG.description,
type: 'website'
}
return {
props: {
page: 1, // current page is 1
posts,
tags
tags,
meta
},
revalidate: 1
}
}
const index = ({ posts, page, tags }) => {
const index = ({ posts, page, tags, meta }) => {
return (
<IndexLayout tags={tags} posts={posts} page={page} />
<IndexLayout tags={tags} posts={posts} page={page} meta={meta} />
)
}

View File

@@ -15,25 +15,12 @@ const Page = ({ posts, tags, page }) => {
})
}
}
return <PageLayout tags={tags} posts={filteredBlogPosts} page={page} />
}
export async function getStaticProps (context) {
const { page } = context.params // Get Current Page No.
let posts = await getAllPosts()
posts = posts.filter(
post => post.status[0] === 'Published' && post.type[0] === 'Post'
)
const tags = await getAllTags(posts)
return {
props: {
tags,
posts,
page
},
revalidate: 1
const meta = {
title: `${BLOG.title} | 博客列表`,
description: BLOG.description,
type: 'website'
}
return <PageLayout tags={tags} posts={filteredBlogPosts} page={page} meta={meta} />
}
export async function getStaticPaths () {
@@ -60,4 +47,21 @@ export async function getStaticPaths () {
}
}
export async function getStaticProps (context) {
const { page } = context.params // Get Current Page No.
let posts = await getAllPosts()
posts = posts.filter(
post => post.status[0] === 'Published' && post.type[0] === 'Post'
)
const tags = await getAllTags(posts)
return {
props: {
tags,
posts,
page
},
revalidate: 1
}
}
export default Page

View File

@@ -1,9 +1,14 @@
import { getAllPosts, getAllTags } from '@/lib/notion'
import IndexLayout from '@/layouts/IndexLayout'
import BLOG from '@/blog.config'
import PageLayout from '@/layouts/PageLayout'
export default function Tag ({ tags, posts, currentTag }) {
return <IndexLayout tags={tags} posts={posts} currentTag={currentTag} />
const meta = {
title: `${BLOG.title} | ${currentTag}`,
description: BLOG.description,
type: 'website'
}
return <PageLayout tags={tags} posts={posts} currentTag={currentTag} meta={meta} />
}
export async function getStaticProps ({ params }) {