From 3c280ddf5867fd435f23ef8cc4e5077725a5d266 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 3 Feb 2023 13:46:30 +0800 Subject: [PATCH] =?UTF-8?q?example=20=E4=B8=BB=E9=A2=98=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=20tag\category=20=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getNotionData.js | 2 +- pages/category/[category]/index.js | 6 +++--- pages/category/[category]/page/[page].js | 4 ++-- pages/category/index.js | 3 --- pages/tag/[tag]/index.js | 4 ++-- pages/tag/[tag]/page/[page].js | 4 ++-- pages/tag/index.js | 3 --- themes/example/LayoutCategoryIndex.js | 7 +++---- themes/example/LayoutTagIndex.js | 8 ++++---- themes/example/components/SideBar.js | 10 +++++----- themes/hexo/LayoutCategoryIndex.js | 4 ++-- themes/hexo/LayoutTag.js | 2 +- themes/hexo/LayoutTagIndex.js | 4 ++-- 13 files changed, 27 insertions(+), 34 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 683754b1..f865d4ed 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -35,7 +35,7 @@ export async function getGlobalNotionData({ delete notionPageData.collectionQuery delete notionPageData.collectionId delete notionPageData.collectionView - + console.log(notionPageData) return notionPageData } diff --git a/pages/category/[category]/index.js b/pages/category/[category]/index.js index eaf8436a..583a69ab 100644 --- a/pages/category/[category]/index.js +++ b/pages/category/[category]/index.js @@ -58,10 +58,10 @@ export async function getStaticProps({ params: { category } }) { export async function getStaticPaths() { const from = 'category-paths' - const { categories } = await getGlobalNotionData({ from }) + const { categoryOptions } = await getGlobalNotionData({ from }) return { - paths: Object.keys(categories).map(category => ({ - params: { category: categories[category]?.name } + paths: Object.keys(categoryOptions).map(category => ({ + params: { category: categoryOptions[category]?.name } })), fallback: true } diff --git a/pages/category/[category]/page/[page].js b/pages/category/[category]/page/[page].js index 06b66a21..f01ae27a 100644 --- a/pages/category/[category]/page/[page].js +++ b/pages/category/[category]/page/[page].js @@ -53,10 +53,10 @@ export async function getStaticProps({ params: { category, page } }) { export async function getStaticPaths() { const from = 'category-paths' - const { categories, allPages } = await getGlobalNotionData({ from }) + const { categoryOptions, allPages } = await getGlobalNotionData({ from }) const paths = [] - categories?.forEach(category => { + categoryOptions?.forEach(category => { // 过滤状态类型 const categoryPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category.name)) // 处理文章页数 diff --git a/pages/category/index.js b/pages/category/index.js index 24653c8c..b310c188 100644 --- a/pages/category/index.js +++ b/pages/category/index.js @@ -2,7 +2,6 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' import React from 'react' import { useGlobal } from '@/lib/global' import * as ThemeMap from '@/themes' -import { getAllCategories } from '@/lib/notion/getAllCategories' import BLOG from '@/blog.config' /** @@ -27,8 +26,6 @@ export default function Category(props) { export async function getStaticProps() { const props = await getGlobalNotionData({ from: 'category-index-props' }) - props.categories = getAllCategories({ allPages: props.allPages, categoryOptions: props.categoryOptions, sliceCount: 0 }) - delete props.categoryOptions delete props.allPages return { props, diff --git a/pages/tag/[tag]/index.js b/pages/tag/[tag]/index.js index 593bf555..f633c94f 100644 --- a/pages/tag/[tag]/index.js +++ b/pages/tag/[tag]/index.js @@ -63,8 +63,8 @@ function getTagNames(tags) { export async function getStaticPaths() { const from = 'tag-static-path' - const { tags } = await getGlobalNotionData({ from }) - const tagNames = getTagNames(tags) + const { tagOptions } = await getGlobalNotionData({ from }) + const tagNames = getTagNames(tagOptions) return { paths: Object.keys(tagNames).map(index => ({ diff --git a/pages/tag/[tag]/page/[page].js b/pages/tag/[tag]/page/[page].js index a21e46b4..788473b9 100644 --- a/pages/tag/[tag]/page/[page].js +++ b/pages/tag/[tag]/page/[page].js @@ -44,9 +44,9 @@ export async function getStaticProps({ params: { tag, page } }) { export async function getStaticPaths() { const from = 'tag-page-static-path' - const { tags, allPages } = await getGlobalNotionData({ from }) + const { tagOptions, allPages } = await getGlobalNotionData({ from }) const paths = [] - tags?.forEach(tag => { + tagOptions?.forEach(tag => { // 过滤状态类型 const tagPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.tags && post.tags.includes(tag.name)) // 处理文章页数 diff --git a/pages/tag/index.js b/pages/tag/index.js index cddba52a..e9263668 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -2,7 +2,6 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' import React from 'react' import { useGlobal } from '@/lib/global' import * as ThemeMap from '@/themes' -import { getAllTags } from '@/lib/notion' import BLOG from '@/blog.config' /** @@ -28,8 +27,6 @@ const TagIndex = props => { export async function getStaticProps() { const from = 'tag-index-props' const props = await getGlobalNotionData({ from }) - props.tags = getAllTags({ allPages: props.allPages, sliceCount: 0, tagOptions: props.tagOptions }) - delete props.tagOptions delete props.allPages return { props, diff --git a/themes/example/LayoutCategoryIndex.js b/themes/example/LayoutCategoryIndex.js index 1230c20f..a4c19033 100644 --- a/themes/example/LayoutCategoryIndex.js +++ b/themes/example/LayoutCategoryIndex.js @@ -1,13 +1,12 @@ import Link from 'next/link' import LayoutBase from './LayoutBase' -export const LayoutCategoryIndex = (props) => { - const { categories } = props - +export const LayoutCategoryIndex = props => { + const { categoryOptions } = props return (
- {categories && categories.map(category => { + {categoryOptions?.map(category => { return ( { - const { tags } = props + const { tagOptions } = props return (
- {tags.map(tag => { + {tagOptions.map(tag => { return (
{
- ); + ) })}
- ); + ) } diff --git a/themes/example/components/SideBar.js b/themes/example/components/SideBar.js index 986063b0..742e661d 100644 --- a/themes/example/components/SideBar.js +++ b/themes/example/components/SideBar.js @@ -7,7 +7,7 @@ const ExampleRecentComments = dynamic(() => import('./ExampleRecentComments')) export const SideBar = (props) => { const { locale } = useGlobal() - const { latestPosts, categories } = props + const { latestPosts, categoryOptions } = props return (
@@ -16,7 +16,7 @@ export const SideBar = (props) => {
@@ -42,7 +42,7 @@ export const SideBar = (props) => {
  • {p.title}
  • - ); + ) })}
    @@ -61,5 +61,5 @@ export const SideBar = (props) => {
    - ); + ) } diff --git a/themes/hexo/LayoutCategoryIndex.js b/themes/hexo/LayoutCategoryIndex.js index 7d7165a6..fc03ded2 100644 --- a/themes/hexo/LayoutCategoryIndex.js +++ b/themes/hexo/LayoutCategoryIndex.js @@ -4,7 +4,7 @@ import Card from './components/Card' import LayoutBase from './LayoutBase' export const LayoutCategoryIndex = props => { - const { categories } = props + const { categoryOptions } = props const { locale } = useGlobal() return ( @@ -14,7 +14,7 @@ export const LayoutCategoryIndex = props => { {locale.COMMON.CATEGORY}:
    - {categories.map(category => { + {categoryOptions.map(category => { return ( { - const tag = props.tags.find((t) => { + const tag = props.tagOptions.find((t) => { return t.name === props.tag }) diff --git a/themes/hexo/LayoutTagIndex.js b/themes/hexo/LayoutTagIndex.js index 7649a704..b754e1e3 100644 --- a/themes/hexo/LayoutTagIndex.js +++ b/themes/hexo/LayoutTagIndex.js @@ -4,7 +4,7 @@ import TagItemMini from './components/TagItemMini' import LayoutBase from './LayoutBase' export const LayoutTagIndex = props => { - const { tags } = props + const { tagOptions } = props const { locale } = useGlobal() return ( @@ -14,7 +14,7 @@ export const LayoutTagIndex = props => { {locale.COMMON.TAGS}:
    - {tags.map(tag => { + {tagOptions.map(tag => { return (