动态主题初版本完成

This commit is contained in:
tangly1024
2022-03-09 17:28:47 +08:00
parent 69422fff7f
commit 24007eed1a
17 changed files with 58 additions and 49 deletions

View File

@@ -1,4 +1,5 @@
import { useGlobal } from '@/lib/global'
import * as ThemeMap from '@/themes'
/**
* 自定义404界面
@@ -7,7 +8,7 @@ import { useGlobal } from '@/lib/global'
*/
export default function Custom404 (props) {
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.Layout404 {...props}/>
}

View File

@@ -3,6 +3,7 @@ import { getPostBlocks } from '@/lib/notion'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import { useGlobal } from '@/lib/global'
import Custom404 from './404'
import * as ThemeMap from '@/themes'
/**
* 根据notion的slug访问页面针对类型为Page的页面
@@ -10,7 +11,8 @@ import Custom404 from './404'
* @returns
*/
const Slug = (props) => {
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
if (!props.post) {
return <Custom404 {...props} />
}

View File

@@ -1,9 +1,11 @@
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import React from 'react'
import { useGlobal } from '@/lib/global'
import * as ThemeMap from '@/themes'
const ArchiveIndex = (props) => {
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutArchive {...props}/>
}

View File

@@ -3,6 +3,7 @@ import { getPostBlocks } from '@/lib/notion'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import { useGlobal } from '@/lib/global'
import Custom404 from '../404'
import * as ThemeMap from '@/themes'
/**
* 根据notion的slug访问页面
@@ -10,7 +11,8 @@ import Custom404 from '../404'
* @returns
*/
const Slug = (props) => {
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
if (!props.post) {
return <Custom404 {...props} />
}

View File

@@ -1,9 +1,11 @@
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import React from 'react'
import { useGlobal } from '@/lib/global'
import * as ThemeMap from '@/themes'
export default function Category (props) {
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutCategory {...props} />
}

View File

@@ -1,9 +1,11 @@
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import React from 'react'
import { useGlobal } from '@/lib/global'
import * as ThemeMap from '@/themes'
export default function Category (props) {
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutCategoryIndex {...props}/>
}

View File

@@ -1,12 +1,11 @@
import BLOG from '@/blog.config'
import { getPostBlocks } from '@/lib/notion'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import * as ThemeMap from '@/themes'
import { useGlobal } from '@/lib/global'
const Index = (props) => {
const { ThemeComponents } = useGlobal()
// return <ThemeComponents.Next.LayoutIndex {...props}/>
console.log(ThemeComponents)
// return <></>
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutIndex {...props}/>
}

View File

@@ -3,9 +3,11 @@ import { getPostBlocks } from '@/lib/notion'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import { useGlobal } from '@/lib/global'
import Custom404 from '../404'
import * as ThemeMap from '@/themes'
const Page = (props) => {
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
if (!props?.meta) {
return <Custom404 {...props} />
}

View File

@@ -2,6 +2,7 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import BLOG from '@/blog.config'
import { useGlobal } from '@/lib/global'
import { getDataFromCache } from '@/lib/cache/cache_manager'
import * as ThemeMap from '@/themes'
const Index = (props) => {
const { keyword } = props
@@ -12,7 +13,8 @@ const Index = (props) => {
type: 'website'
}
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutSearch {...props} meta={meta} currentSearch={keyword} />
}

View File

@@ -2,31 +2,7 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import BLOG from '@/blog.config'
import { useGlobal } from '@/lib/global'
import { useRouter } from 'next/router'
/**
* 浏览器前端搜索
*/
export async function getStaticProps () {
const {
allPosts,
categories,
tags,
postCount,
latestPosts,
customNav
} = await getGlobalNotionData({ from: 'search-props', pageType: ['Post'] })
return {
props: {
posts: allPosts,
tags,
categories,
postCount,
latestPosts,
customNav
},
revalidate: 1
}
}
import * as ThemeMap from '@/themes'
const Search = (props) => {
const { posts } = props
@@ -51,11 +27,30 @@ const Search = (props) => {
type: 'website'
}
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutSearch {...props} posts={filteredPosts} meta={meta} currentSearch={searchKey} />
}
/**
* 浏览器前端搜索
*/
export async function getStaticProps () {
const { allPosts, categories, tags, postCount, latestPosts, customNav } = await getGlobalNotionData({ from: 'search-props', pageType: ['Post'] })
return {
props: {
posts: allPosts,
tags,
categories,
postCount,
latestPosts,
customNav
},
revalidate: 1
}
}
function getSearchKey () {
const router = useRouter()
if (router.query && router.query.s) {

View File

@@ -1,8 +1,10 @@
import { useGlobal } from '@/lib/global'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import * as ThemeMap from '@/themes'
const Tag = (props) => {
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutTag {...props} />
}

View File

@@ -1,9 +1,11 @@
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import React from 'react'
import { useGlobal } from '@/lib/global'
import * as ThemeMap from '@/themes'
const TagIndex = (props) => {
const { ThemeComponents } = useGlobal()
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutTagIndex {...props} />
}