重构;DynamicLayout组件重写,移除blog.config.js中的MAPPING配置

This commit is contained in:
tangly1024
2024-11-23 18:24:47 +08:00
parent be1ada5106
commit 394c8e0e0b
21 changed files with 55 additions and 73 deletions

View File

@@ -2,7 +2,6 @@ import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
/**
* 404
@@ -10,9 +9,8 @@ import { useRouter } from 'next/router'
* @returns
*/
const NoFound = props => {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='Layout404' {...props} />
}
export async function getStaticProps(req) {

View File

@@ -87,7 +87,7 @@ const Slug = props => {
return (
<>
{/* 文章布局 */}
<DynamicLayout theme={theme} router={router} {...props} />
<DynamicLayout theme={theme} layoutName='LayoutSlug' {...props} />
{/* 解锁密码提示框 */}
{post?.password && post?.password !== '' && !lock && <Notification />}
{/* 导流工具 */}

View File

@@ -8,7 +8,7 @@ import 'react-notion-x/src/styles.css' // 原版的react-notion-x
import useAdjustStyle from '@/hooks/useAdjustStyle'
import { GlobalContextProvider } from '@/lib/global'
import { getGlobalLayoutByTheme } from '@/themes/theme'
import { getBaseLayoutByTheme } from '@/themes/theme'
import { useRouter } from 'next/router'
import { useCallback, useMemo } from 'react'
import { getQueryParam } from '../lib/utils'
@@ -34,7 +34,7 @@ const MyApp = ({ Component, pageProps }) => {
useAdjustStyle()
const route = useRouter()
const queryParam = useMemo(() => {
const theme = useMemo(() => {
return (
getQueryParam(route.asPath, 'theme') ||
pageProps?.NOTION_CONFIG?.THEME ||
@@ -45,10 +45,10 @@ const MyApp = ({ Component, pageProps }) => {
// 整体布局
const GLayout = useCallback(
props => {
const Layout = getGlobalLayoutByTheme(queryParam)
const Layout = getBaseLayoutByTheme(theme)
return <Layout {...props} />
},
[queryParam]
[theme]
)
const enableClerk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY

View File

@@ -4,7 +4,6 @@ import { getGlobalData } from '@/lib/db/getSiteData'
import { isBrowser } from '@/lib/utils'
import { formatDateFmt } from '@/lib/utils/formatDate'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
import { useEffect } from 'react'
/**
@@ -27,9 +26,8 @@ const ArchiveIndex = props => {
}
}, [])
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutArchive' {...props} />
}
export async function getStaticProps({ locale }) {

View File

@@ -2,7 +2,6 @@ import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
/**
* 分类页
@@ -10,9 +9,8 @@ import { useRouter } from 'next/router'
* @returns
*/
export default function Category(props) {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutPostList' {...props} />
}
export async function getStaticProps({ params: { category }, locale }) {

View File

@@ -2,7 +2,6 @@ import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
/**
* 分类页
@@ -11,9 +10,8 @@ import { useRouter } from 'next/router'
*/
export default function Category(props) {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutPostList' {...props} />
}
export async function getStaticProps({ params: { category, page } }) {

View File

@@ -2,7 +2,6 @@ import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
/**
* 分类首页
@@ -10,9 +9,8 @@ import { useRouter } from 'next/router'
* @returns
*/
export default function Category(props) {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutPostList' {...props} />
}
export async function getStaticProps({ locale }) {

View File

@@ -2,7 +2,6 @@ import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { getGlobalData, getPost, getPostBlocks } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
/**
* 根据notion的slug访问页面
@@ -11,9 +10,8 @@ import { useRouter } from 'next/router'
* @returns
*/
const Dashboard = props => {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutDashboard' {...props} />
}
export async function getStaticProps({ locale }) {

View File

@@ -5,7 +5,6 @@ import { generateRobotsTxt } from '@/lib/robots.txt'
import { generateRss } from '@/lib/rss'
import { generateSitemapXml } from '@/lib/sitemap.xml'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
/**
* 首页布局
@@ -13,9 +12,8 @@ import { useRouter } from 'next/router'
* @returns
*/
const Index = props => {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutIndex' {...props} />
}
/**

View File

@@ -2,7 +2,6 @@ import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { getGlobalData, getPostBlocks } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
/**
* 文章列表分页
@@ -10,9 +9,8 @@ import { useRouter } from 'next/router'
* @returns
*/
const Page = props => {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutPostList' {...props} />
}
export async function getStaticPaths({ locale }) {

View File

@@ -3,12 +3,10 @@ import { getDataFromCache } from '@/lib/cache/cache_manager'
import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
const Index = props => {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutSearch' {...props} />
}
/**

View File

@@ -3,15 +3,13 @@ import { getDataFromCache } from '@/lib/cache/cache_manager'
import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
const Index = props => {
const { keyword } = props
props = { ...props, currentSearch: keyword }
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutSearch' {...props} />
}
/**

View File

@@ -32,7 +32,7 @@ const Search = props => {
props = { ...props, posts: filteredPosts }
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutSearch' {...props} />
}
/**

View File

@@ -3,7 +3,6 @@ import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
// import { getGlobalData } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
/**
* 登录
@@ -11,9 +10,8 @@ import { useRouter } from 'next/router'
* @returns
*/
const SignIn = props => {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutSignIn' {...props} />
}
export async function getStaticProps(req) {

View File

@@ -2,7 +2,6 @@ import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
/**
* 注册
@@ -10,9 +9,8 @@ import { useRouter } from 'next/router'
* @returns
*/
const SignUp = props => {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutSignUp' {...props} />
}
export async function getStaticProps(req) {

View File

@@ -2,7 +2,6 @@ import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
/**
* 标签下的文章列表
@@ -10,9 +9,8 @@ import { useRouter } from 'next/router'
* @returns
*/
const Tag = props => {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutPostList' {...props} />
}
export async function getStaticProps({ params: { tag }, locale }) {

View File

@@ -2,12 +2,10 @@ import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
import { DynamicLayout } from '@/themes/theme'
import { useRouter } from 'next/router'
const Tag = props => {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutPostList' {...props} />
}
export async function getStaticProps({ params: { tag, page }, locale }) {

View File

@@ -12,7 +12,7 @@ import { useRouter } from 'next/router'
const TagIndex = props => {
const router = useRouter()
const theme = siteConfig('THEME', BLOG.THEME, props.NOTION_CONFIG)
return <DynamicLayout theme={theme} router={router} {...props} />
return <DynamicLayout theme={theme} layoutName='LayoutPostList' {...props} />
}
export async function getStaticProps(req) {