example 主题 调整 tag\category 结构

This commit is contained in:
tangly1024.com
2023-02-03 13:46:30 +08:00
parent d93f08fe11
commit 3c280ddf58
13 changed files with 27 additions and 34 deletions

View File

@@ -35,7 +35,7 @@ export async function getGlobalNotionData({
delete notionPageData.collectionQuery
delete notionPageData.collectionId
delete notionPageData.collectionView
console.log(notionPageData)
return notionPageData
}

View File

@@ -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
}

View File

@@ -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))
// 处理文章页数

View File

@@ -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,

View File

@@ -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 => ({

View File

@@ -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))
// 处理文章页数

View File

@@ -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,

View File

@@ -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 (
<LayoutBase {...props}>
<div id='category-list' className='duration-200 flex flex-wrap'>
{categories && categories.map(category => {
{categoryOptions?.map(category => {
return (
<Link
key={category.name}

View File

@@ -2,12 +2,12 @@ import Link from 'next/link'
import LayoutBase from './LayoutBase'
export const LayoutTagIndex = (props) => {
const { tags } = props
const { tagOptions } = props
return (
<LayoutBase {...props}>
<div>
<div id='tags-list' className='duration-200 flex flex-wrap'>
{tags.map(tag => {
{tagOptions.map(tag => {
return (
<div key={tag.name} className='p-2'>
<Link
@@ -21,9 +21,9 @@ export const LayoutTagIndex = (props) => {
</Link>
</div>
);
)
})}
</div>
</div> </LayoutBase>
);
)
}

View File

@@ -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 (
<div className="w-full md:w-64 sticky top-8">
@@ -16,7 +16,7 @@ export const SideBar = (props) => {
<div className="p-4">
<ul className="list-reset leading-normal">
{categories?.map(category => {
{categoryOptions?.map(category => {
return (
<Link
key={category.name}
@@ -25,7 +25,7 @@ export const SideBar = (props) => {
legacyBehavior>
<li> <a href="#" className="text-gray-darkest text-sm">{category.name}({category.count})</a></li>
</Link>
);
)
})}
</ul>
</div>
@@ -42,7 +42,7 @@ export const SideBar = (props) => {
<Link key={p.id} href={`/${p.slug}`} passHref legacyBehavior>
<li> <a href="#" className="text-gray-darkest text-sm">{p.title}</a></li>
</Link>
);
)
})}
</ul>
</div>
@@ -61,5 +61,5 @@ export const SideBar = (props) => {
</aside>
</div>
);
)
}

View File

@@ -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 (
<LayoutBase {...props}>
@@ -14,7 +14,7 @@ export const LayoutCategoryIndex = props => {
{locale.COMMON.CATEGORY}:
</div>
<div id="category-list" className="duration-200 flex flex-wrap mx-8">
{categories.map(category => {
{categoryOptions.map(category => {
return (
<Link
key={category.name}

View File

@@ -6,7 +6,7 @@ import React from 'react'
import Link from 'next/link'
export const LayoutTag = (props) => {
const tag = props.tags.find((t) => {
const tag = props.tagOptions.find((t) => {
return t.name === props.tag
})

View File

@@ -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 (
<LayoutBase {...props}>
@@ -14,7 +14,7 @@ export const LayoutTagIndex = props => {
{locale.COMMON.TAGS}:
</div>
<div id="tags-list" className="duration-200 flex flex-wrap ml-8">
{tags.map(tag => {
{tagOptions.map(tag => {
return (
<div key={tag.name} className="p-2">
<TagItemMini key={tag.name} tag={tag} />