-
- {post.slug !== 'about' && (<>
-
-
-
- >)}
- {post.tags && (
-
- {post.tags.map(tag => (
-
- ))}
-
- )}
+
{post.category}
{post.type[0] !== 'Page' && (
@@ -93,6 +78,15 @@ const ArticleDetail = ({ post, blockMap, tags, prev, next, posts }) => {
)}
)}
+
+ {post.tags && (
+
+ {post.tags.map(tag => (
+
+ ))}
+
+ )}
+
{/* 不蒜子 */}
@@ -141,10 +135,10 @@ const ArticleDetail = ({ post, blockMap, tags, prev, next, posts }) => {
{/* 评论互动 */}
@@ -198,13 +192,15 @@ export async function getStaticProps ({ params: { slug } }) {
}
posts = posts.filter(post => post.type[0] === 'Post')
const tags = await getAllTags(posts)
+ const categories = await getAllCategories(posts)
+
// 获取推荐文章
const index = posts.indexOf(post)
const prev = posts.slice(index - 1, index)[0] ?? posts.slice(-1)[0]
const next = posts.slice(index + 1, index + 2)[0] ?? posts[0]
return {
- props: { post, blockMap, tags, prev, next, posts },
+ props: { post, blockMap, tags, prev, next, posts, categories },
revalidate: 1
}
}
diff --git a/pages/category/[category].js b/pages/category/[category].js
new file mode 100644
index 00000000..64ebc902
--- /dev/null
+++ b/pages/category/[category].js
@@ -0,0 +1,56 @@
+import { getAllCategories, getAllPosts, getAllTags } from '@/lib/notion'
+import BLOG from '@/blog.config'
+import TagsBar from '@/components/TagsBar'
+import BaseLayout from '@/layouts/BaseLayout'
+import BlogPostListScroll from '@/components/BlogPostListScroll'
+
+export default function Category ({ tags, posts, category, categories }) {
+ const meta = {
+ title: `${BLOG.title} | ${category}`,
+ description: BLOG.description,
+ type: 'website'
+ }
+ return
+
+
+
+
+
+}
+
+export async function getStaticProps ({ params }) {
+ const category = params.category
+ let posts = await getAllPosts({ from: 'category-props' })
+ posts = posts.filter(
+ post => post.status[0] === 'Published' && post.type[0] === 'Post'
+ )
+ const tags = await getAllTags(posts)
+ const categories = await getAllCategories(posts)
+ const filteredPosts = posts.filter(
+ post => post && post.category && post.category.includes(category)
+ )
+ return {
+ props: {
+ tags,
+ posts: filteredPosts,
+ category,
+ categories
+ },
+ revalidate: 1
+ }
+}
+
+export async function getStaticPaths () {
+ if (BLOG.isProd) {
+ const tags = await getAllTags()
+ return {
+ paths: Object.keys(tags).map(tag => ({ params: { tag } })),
+ fallback: true
+ }
+ } else {
+ return {
+ paths: [],
+ fallback: true
+ }
+ }
+}
diff --git a/pages/index.js b/pages/index.js
index f1fff823..86acb8c9 100644
--- a/pages/index.js
+++ b/pages/index.js
@@ -1,4 +1,4 @@
-import { getAllPosts, getAllTags } from '@/lib/notion'
+import { getAllPosts, getAllTags, getAllCategories } from '@/lib/notion'
import BLOG from '@/blog.config'
import BaseLayout from '@/layouts/BaseLayout'
import TagsBar from '@/components/TagsBar'
@@ -10,6 +10,7 @@ export async function getStaticProps () {
post => post.status[0] === 'Published' && post.type[0] === 'Post'
)
const tags = await getAllTags(posts)
+ const categories = await getAllCategories(posts)
const meta = {
title: `${BLOG.title} | ${BLOG.description} `,
description: BLOG.description,
@@ -19,15 +20,16 @@ export async function getStaticProps () {
props: {
posts,
tags,
+ categories,
meta
},
revalidate: 1
}
}
-const Index = ({ posts, tags, meta }) => {
+const Index = ({ posts, tags, meta, categories }) => {
return (
-
+
diff --git a/pages/search.js b/pages/search.js
index b462c9bf..b7095202 100644
--- a/pages/search.js
+++ b/pages/search.js
@@ -1,4 +1,4 @@
-import { getAllPosts, getAllTags } from '@/lib/notion'
+import { getAllCategories, getAllPosts, getAllTags } from '@/lib/notion'
import BLOG from '@/blog.config'
import BaseLayout from '@/layouts/BaseLayout'
import TagsBar from '@/components/TagsBar'
@@ -11,6 +11,8 @@ export async function getStaticProps () {
post => post.status[0] === 'Published' && post.type[0] === 'Post'
)
const tags = await getAllTags(posts)
+ const categories = await getAllCategories(posts)
+
const meta = {
title: `${BLOG.title} | ${BLOG.description} `,
description: BLOG.description,
@@ -20,13 +22,14 @@ export async function getStaticProps () {
props: {
posts,
tags,
- meta
+ meta,
+ categories
},
revalidate: 1
}
}
-const Search = ({ posts, tags, meta }) => {
+const Search = ({ posts, tags, meta, categories }) => {
// 处理查询过滤 支持标签、关键词过滤
let filteredPosts = []
const searchKey = getSearchKey()
@@ -38,10 +41,10 @@ const Search = ({ posts, tags, meta }) => {
})
}
return (
-
+
-
+
)
diff --git a/pages/tag/[tag].js b/pages/tag/[tag].js
index 06be98fe..74da8e04 100644
--- a/pages/tag/[tag].js
+++ b/pages/tag/[tag].js
@@ -1,19 +1,19 @@
-import { getAllPosts, getAllTags } from '@/lib/notion'
+import { getAllCategories, getAllPosts, getAllTags } from '@/lib/notion'
import BLOG from '@/blog.config'
import TagsBar from '@/components/TagsBar'
-import BlogPostListPage from '@/components/BlogPostListPage'
import BaseLayout from '@/layouts/BaseLayout'
+import BlogPostListScroll from '@/components/BlogPostListScroll'
-export default function Tag ({ tags, posts, currentTag }) {
+export default function Tag ({ tags, posts, currentTag, categories }) {
const meta = {
- title: `${BLOG.title} | ${currentTag}`,
+ title: `${BLOG.title} | #${currentTag}`,
description: BLOG.description,
type: 'website'
}
- return
-
+ return
+
-
+
}
@@ -25,6 +25,7 @@ export async function getStaticProps ({ params }) {
post => post.status[0] === 'Published' && post.type[0] === 'Post'
)
const tags = await getAllTags(posts)
+ const categories = await getAllCategories(posts)
const filteredPosts = posts.filter(
post => post && post.tags && post.tags.includes(currentTag)
)
@@ -32,7 +33,8 @@ export async function getStaticProps ({ params }) {
props: {
tags,
posts: filteredPosts,
- currentTag
+ currentTag,
+ categories
},
revalidate: 1
}