'use client' import CONFIG from './config' import TopNav from './components/TopNav' import AsideLeft from './components/AsideLeft' import BLOG from '@/blog.config' import { isBrowser } from '@/lib/utils' import { useGlobal } from '@/lib/global' import BlogListPage from './components/BlogListPage' import BlogListScroll from './components/BlogListScroll' import BlogArchiveItem from './components/BlogPostArchive' import ArticleDetail from './components/ArticleDetail' import ArticleLock from './components/ArticleLock' import TagItemMini from './components/TagItemMini' import { useRouter } from 'next/router' import { createContext, useContext, useEffect, useState } from 'react' import Link from 'next/link' import { Transition } from '@headlessui/react' import dynamic from 'next/dynamic' import { AdSlot } from '@/components/GoogleAdsense' import { Style } from './style' import replaceSearchResult from '@/components/Mark' import CommonHead from '@/components/CommonHead' const Live2D = dynamic(() => import('@/components/Live2D')) // 主题全局状态 const ThemeGlobalFukasawa = createContext() export const useFukasawaGlobal = () => useContext(ThemeGlobalFukasawa) /** * 基础布局 采用左右两侧布局,移动端使用顶部导航栏 * @param children * @param layout * @param tags * @param meta * @param post * @param currentSearch * @param currentCategory * @param currentTag * @param categories * @returns {JSX.Element} * @constructor */ const LayoutBase = (props) => { const { children, headerSlot, meta } = props const leftAreaSlot = const { onLoading } = useGlobal() // 侧边栏折叠从 本地存储中获取 open 状态的初始值 const [isCollapsed, setIsCollapse] = useState(() => { if (typeof window !== 'undefined') { return localStorage.getItem('fukasawa-sidebar-collapse') === 'true' || CONFIG.SIDEBAR_COLLAPSE_SATUS_DEFAULT } return CONFIG.SIDEBAR_COLLAPSE_SATUS_DEFAULT }) // 在组件卸载时保存 open 状态到本地存储中 useEffect(() => { if (isBrowser) { localStorage.setItem('fukasawa-sidebar-collapse', isCollapsed) } }, [isCollapsed]) return ( {/* SEO信息 */} {/* 侧边抽屉 */} {headerSlot} {children} ) } /** * 首页 * @param {*} props notion数据 * @returns 首页就是一个博客列表 */ const LayoutIndex = (props) => { return } /** * 博客列表 * @param {*} props */ const LayoutPostList = (props) => { return {BLOG.POST_LIST_STYLE === 'page' ? : } } /** * 文章详情 * @param {*} props * @returns */ const LayoutSlug = (props) => { const { lock, validPassword } = props return ( {lock ? : } ) } /** * 搜索页 */ const LayoutSearch = props => { const { keyword } = props const router = useRouter() useEffect(() => { if (isBrowser) { replaceSearchResult({ doms: document.getElementById('posts-wrapper'), search: keyword, target: { element: 'span', className: 'text-red-500 border-b border-dashed' } }) } }, [router]) return } /** * 归档页面 */ const LayoutArchive = (props) => { const { archivePosts } = props return {Object.keys(archivePosts).map(archiveTitle => ( ))} } /** * 404 * @param {*} props * @returns */ const Layout404 = props => { return 404 } /** * 分类列表 * @param {*} props * @returns */ const LayoutCategoryIndex = (props) => { const { locale } = useGlobal() const { categoryOptions } = props return ( {locale.COMMON.CATEGORY}: {categoryOptions?.map(category => { return ( {category.name}({category.count}) ) })} ) } /** * 标签列表 * @param {*} props * @returns */ const LayoutTagIndex = (props) => { const { locale } = useGlobal() const { tagOptions } = props return {locale.COMMON.TAGS}: {tagOptions.map(tag => { return ( ) })} } export { CONFIG as THEME_CONFIG, LayoutIndex, LayoutSearch, LayoutArchive, LayoutSlug, Layout404, LayoutPostList, LayoutCategoryIndex, LayoutTagIndex }