Skip to content

Commit 24007ee

Browse files
committed
动态主题初版本完成
1 parent 69422ff commit 24007ee

File tree

17 files changed

+58
-49
lines changed

17 files changed

+58
-49
lines changed

jsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"@/*": ["./*"],
66
"@/components/*": ["components/*"],
77
"@/data/*": ["data/*"],
8-
"@/layouts/*": ["theme/*"],
98
"@/lib/*": ["lib/*"],
109
"@/styles/*": ["styles/*"]
1110
}

lib/global.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useContext, createContext, useState } from 'react'
33
import Router from 'next/router'
44
import { initDarkMode } from './theme'
55
import BLOG from '@/blog.config'
6-
import * as ThemeMap from '@/themes'
76
const GlobalContext = createContext()
87
let hasInit = false
98

@@ -18,8 +17,6 @@ export function GlobalContextProvider ({ children }) {
1817
const [isDarkMode, updateDarkMode] = useState(false)
1918
const [onLoading, changeLoadingState] = useState(false)
2019
const [theme, setTheme] = useState(BLOG.THEME)
21-
console.log('ThemeMap', ThemeMap)
22-
const ThemeComponents = ThemeMap[theme]
2320

2421
Router.events.on('routeChangeStart', (...args) => {
2522
changeLoadingState(true)
@@ -39,7 +36,7 @@ export function GlobalContextProvider ({ children }) {
3936
}, 100)
4037

4138
return (
42-
<GlobalContext.Provider value={{ onLoading, locale, isDarkMode, updateDarkMode, theme, setTheme, ThemeComponents }}>
39+
<GlobalContext.Provider value={{ onLoading, locale, isDarkMode, updateDarkMode, theme, setTheme }}>
4340
{children}
4441
</GlobalContext.Provider>
4542
)

pages/404.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useGlobal } from '@/lib/global'
2+
import * as ThemeMap from '@/themes'
23

34
/**
45
* 自定义404界面
@@ -7,7 +8,7 @@ import { useGlobal } from '@/lib/global'
78
*/
89

910
export default function Custom404 (props) {
10-
const { ThemeComponents } = useGlobal()
11-
11+
const { theme } = useGlobal()
12+
const ThemeComponents = ThemeMap[theme]
1213
return <ThemeComponents.Layout404 {...props}/>
1314
}

pages/[slug].js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import { getPostBlocks } from '@/lib/notion'
33
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
44
import { useGlobal } from '@/lib/global'
55
import Custom404 from './404'
6+
import * as ThemeMap from '@/themes'
67

78
/**
89
* 根据notion的slug访问页面,针对类型为Page的页面
910
* @param {*} props
1011
* @returns
1112
*/
1213
const Slug = (props) => {
13-
const { ThemeComponents } = useGlobal()
14+
const { theme } = useGlobal()
15+
const ThemeComponents = ThemeMap[theme]
1416
if (!props.post) {
1517
return <Custom404 {...props} />
1618
}

pages/archive/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
22
import React from 'react'
33
import { useGlobal } from '@/lib/global'
4+
import * as ThemeMap from '@/themes'
45

56
const ArchiveIndex = (props) => {
6-
const { ThemeComponents } = useGlobal()
7+
const { theme } = useGlobal()
8+
const ThemeComponents = ThemeMap[theme]
79
return <ThemeComponents.LayoutArchive {...props}/>
810
}
911

pages/article/[slug].js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import { getPostBlocks } from '@/lib/notion'
33
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
44
import { useGlobal } from '@/lib/global'
55
import Custom404 from '../404'
6+
import * as ThemeMap from '@/themes'
67

78
/**
89
* 根据notion的slug访问页面
910
* @param {*} props
1011
* @returns
1112
*/
1213
const Slug = (props) => {
13-
const { ThemeComponents } = useGlobal()
14+
const { theme } = useGlobal()
15+
const ThemeComponents = ThemeMap[theme]
1416
if (!props.post) {
1517
return <Custom404 {...props} />
1618
}

pages/category/[category].js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
22
import React from 'react'
33
import { useGlobal } from '@/lib/global'
4+
import * as ThemeMap from '@/themes'
45

56
export default function Category (props) {
6-
const { ThemeComponents } = useGlobal()
7+
const { theme } = useGlobal()
8+
const ThemeComponents = ThemeMap[theme]
79
return <ThemeComponents.LayoutCategory {...props} />
810
}
911

pages/category/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
22
import React from 'react'
33
import { useGlobal } from '@/lib/global'
4+
import * as ThemeMap from '@/themes'
45

56
export default function Category (props) {
6-
const { ThemeComponents } = useGlobal()
7+
const { theme } = useGlobal()
8+
const ThemeComponents = ThemeMap[theme]
79
return <ThemeComponents.LayoutCategoryIndex {...props}/>
810
}
911

pages/index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import BLOG from '@/blog.config'
22
import { getPostBlocks } from '@/lib/notion'
33
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
4+
import * as ThemeMap from '@/themes'
45
import { useGlobal } from '@/lib/global'
56
const Index = (props) => {
6-
const { ThemeComponents } = useGlobal()
7-
// return <ThemeComponents.Next.LayoutIndex {...props}/>
8-
console.log(ThemeComponents)
9-
// return <></>
7+
const { theme } = useGlobal()
8+
const ThemeComponents = ThemeMap[theme]
109
return <ThemeComponents.LayoutIndex {...props}/>
1110
}
1211

pages/page/[page].js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { getPostBlocks } from '@/lib/notion'
33
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
44
import { useGlobal } from '@/lib/global'
55
import Custom404 from '../404'
6+
import * as ThemeMap from '@/themes'
67

78
const Page = (props) => {
8-
const { ThemeComponents } = useGlobal()
9+
const { theme } = useGlobal()
10+
const ThemeComponents = ThemeMap[theme]
911
if (!props?.meta) {
1012
return <Custom404 {...props} />
1113
}

pages/search/[keyword].js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData'
22
import BLOG from '@/blog.config'
33
import { useGlobal } from '@/lib/global'
44
import { getDataFromCache } from '@/lib/cache/cache_manager'
5+
import * as ThemeMap from '@/themes'
56

67
const Index = (props) => {
78
const { keyword } = props
@@ -12,7 +13,8 @@ const Index = (props) => {
1213
type: 'website'
1314
}
1415

15-
const { ThemeComponents } = useGlobal()
16+
const { theme } = useGlobal()
17+
const ThemeComponents = ThemeMap[theme]
1618
return <ThemeComponents.LayoutSearch {...props} meta={meta} currentSearch={keyword} />
1719
}
1820

pages/search/index.js

+21-26
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,7 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData'
22
import BLOG from '@/blog.config'
33
import { useGlobal } from '@/lib/global'
44
import { useRouter } from 'next/router'
5-
6-
/**
7-
* 浏览器前端搜索
8-
*/
9-
export async function getStaticProps () {
10-
const {
11-
allPosts,
12-
categories,
13-
tags,
14-
postCount,
15-
latestPosts,
16-
customNav
17-
} = await getGlobalNotionData({ from: 'search-props', pageType: ['Post'] })
18-
return {
19-
props: {
20-
posts: allPosts,
21-
tags,
22-
categories,
23-
postCount,
24-
latestPosts,
25-
customNav
26-
},
27-
revalidate: 1
28-
}
29-
}
5+
import * as ThemeMap from '@/themes'
306

317
const Search = (props) => {
328
const { posts } = props
@@ -51,11 +27,30 @@ const Search = (props) => {
5127
type: 'website'
5228
}
5329

54-
const { ThemeComponents } = useGlobal()
30+
const { theme } = useGlobal()
31+
const ThemeComponents = ThemeMap[theme]
5532

5633
return <ThemeComponents.LayoutSearch {...props} posts={filteredPosts} meta={meta} currentSearch={searchKey} />
5734
}
5835

36+
/**
37+
* 浏览器前端搜索
38+
*/
39+
export async function getStaticProps () {
40+
const { allPosts, categories, tags, postCount, latestPosts, customNav } = await getGlobalNotionData({ from: 'search-props', pageType: ['Post'] })
41+
return {
42+
props: {
43+
posts: allPosts,
44+
tags,
45+
categories,
46+
postCount,
47+
latestPosts,
48+
customNav
49+
},
50+
revalidate: 1
51+
}
52+
}
53+
5954
function getSearchKey () {
6055
const router = useRouter()
6156
if (router.query && router.query.s) {

pages/tag/[tag].js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { useGlobal } from '@/lib/global'
22
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
3+
import * as ThemeMap from '@/themes'
34

45
const Tag = (props) => {
5-
const { ThemeComponents } = useGlobal()
6+
const { theme } = useGlobal()
7+
const ThemeComponents = ThemeMap[theme]
68
return <ThemeComponents.LayoutTag {...props} />
79
}
810

pages/tag/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
22
import React from 'react'
33
import { useGlobal } from '@/lib/global'
4+
import * as ThemeMap from '@/themes'
45

56
const TagIndex = (props) => {
6-
const { ThemeComponents } = useGlobal()
7+
const { theme } = useGlobal()
8+
const ThemeComponents = ThemeMap[theme]
79
return <ThemeComponents.LayoutTagIndex {...props} />
810
}
911

themes/Empty/LayoutPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import LayoutBase from '../Empty/LayoutBase'
1+
import LayoutBase from './LayoutBase'
22

33
export const LayoutPage = (props) => {
44
const { page } = props

themes/Medium/components/BottomMenuBar.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Link from 'next/link'
22
import React from 'react'
3-
import JumpToTopButton from '@/themes/Medium/components/JumpToTopButton'
3+
import JumpToTopButton from './JumpToTopButton'
44

55
export default function BottomMenuBar ({ className }) {
66
return (

themes/Medium/components/TopNavBar.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import LogoBar from '@/themes/Medium/components/LogoBar'
21
import Link from 'next/link'
32
import { useRouter } from 'next/router'
3+
import LogoBar from './LogoBar'
44

55
/**
66
* 顶部导航栏 + 菜单

0 commit comments

Comments
 (0)