diff --git a/jsconfig.json b/jsconfig.json index 9802ad57..f6f71d10 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -5,7 +5,6 @@ "@/*": ["./*"], "@/components/*": ["components/*"], "@/data/*": ["data/*"], - "@/layouts/*": ["theme/*"], "@/lib/*": ["lib/*"], "@/styles/*": ["styles/*"] } diff --git a/lib/global.js b/lib/global.js index 1e1fe572..28b5b292 100644 --- a/lib/global.js +++ b/lib/global.js @@ -3,7 +3,6 @@ import { useContext, createContext, useState } from 'react' import Router from 'next/router' import { initDarkMode } from './theme' import BLOG from '@/blog.config' -import * as ThemeMap from '@/themes' const GlobalContext = createContext() let hasInit = false @@ -18,8 +17,6 @@ export function GlobalContextProvider ({ children }) { const [isDarkMode, updateDarkMode] = useState(false) const [onLoading, changeLoadingState] = useState(false) const [theme, setTheme] = useState(BLOG.THEME) - console.log('ThemeMap', ThemeMap) - const ThemeComponents = ThemeMap[theme] Router.events.on('routeChangeStart', (...args) => { changeLoadingState(true) @@ -39,7 +36,7 @@ export function GlobalContextProvider ({ children }) { }, 100) return ( - + {children} ) diff --git a/pages/404.js b/pages/404.js index b14f859b..29423e5f 100644 --- a/pages/404.js +++ b/pages/404.js @@ -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 } diff --git a/pages/[slug].js b/pages/[slug].js index eda1bc51..d513f334 100644 --- a/pages/[slug].js +++ b/pages/[slug].js @@ -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 } diff --git a/pages/archive/index.js b/pages/archive/index.js index 6d974951..75bf91b1 100644 --- a/pages/archive/index.js +++ b/pages/archive/index.js @@ -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 } diff --git a/pages/article/[slug].js b/pages/article/[slug].js index 29a03539..bfe391d1 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -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 } diff --git a/pages/category/[category].js b/pages/category/[category].js index 3362d419..9e9f5f3f 100644 --- a/pages/category/[category].js +++ b/pages/category/[category].js @@ -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 } diff --git a/pages/category/index.js b/pages/category/index.js index 22232a7d..dd195d4c 100644 --- a/pages/category/index.js +++ b/pages/category/index.js @@ -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 } diff --git a/pages/index.js b/pages/index.js index 601e6671..02a15885 100644 --- a/pages/index.js +++ b/pages/index.js @@ -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 - console.log(ThemeComponents) - // return <> + const { theme } = useGlobal() + const ThemeComponents = ThemeMap[theme] return } diff --git a/pages/page/[page].js b/pages/page/[page].js index 9d879940..0d6c1759 100644 --- a/pages/page/[page].js +++ b/pages/page/[page].js @@ -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 } diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 109768db..c00b6764 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -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 } diff --git a/pages/search/index.js b/pages/search/index.js index f0d266f3..bf0849d4 100644 --- a/pages/search/index.js +++ b/pages/search/index.js @@ -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 } +/** + * 浏览器前端搜索 + */ +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) { diff --git a/pages/tag/[tag].js b/pages/tag/[tag].js index 90a5a9d2..238248bd 100644 --- a/pages/tag/[tag].js +++ b/pages/tag/[tag].js @@ -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 } diff --git a/pages/tag/index.js b/pages/tag/index.js index 90d0b9ec..d8a7911a 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -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 } diff --git a/themes/Empty/LayoutPage.js b/themes/Empty/LayoutPage.js index f25ee48f..661a104b 100644 --- a/themes/Empty/LayoutPage.js +++ b/themes/Empty/LayoutPage.js @@ -1,4 +1,4 @@ -import LayoutBase from '../Empty/LayoutBase' +import LayoutBase from './LayoutBase' export const LayoutPage = (props) => { const { page } = props diff --git a/themes/Medium/components/BottomMenuBar.js b/themes/Medium/components/BottomMenuBar.js index e56b2601..8678afa7 100644 --- a/themes/Medium/components/BottomMenuBar.js +++ b/themes/Medium/components/BottomMenuBar.js @@ -1,6 +1,6 @@ import Link from 'next/link' import React from 'react' -import JumpToTopButton from '@/themes/Medium/components/JumpToTopButton' +import JumpToTopButton from './JumpToTopButton' export default function BottomMenuBar ({ className }) { return ( diff --git a/themes/Medium/components/TopNavBar.js b/themes/Medium/components/TopNavBar.js index fcbb84fc..78daa747 100644 --- a/themes/Medium/components/TopNavBar.js +++ b/themes/Medium/components/TopNavBar.js @@ -1,6 +1,6 @@ -import LogoBar from '@/themes/Medium/components/LogoBar' import Link from 'next/link' import { useRouter } from 'next/router' +import LogoBar from './LogoBar' /** * 顶部导航栏 + 菜单