import CONFIG from './config'
import { createContext, useContext, useEffect, useRef } from 'react'
import { isBrowser } from '@/lib/utils'
import { useGlobal } from '@/lib/global'
import { AdSlot } from '@/components/GoogleAdsense'
import { siteConfig } from '@/lib/config'
import { Transition } from '@headlessui/react'
import Link from 'next/link'
import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
import dynamic from 'next/dynamic'
import NotionPage from '@/components/NotionPage'
import AlgoliaSearchModal from '@/components/AlgoliaSearchModal'
import { LAYOUT_MAPPINGS } from '@/blog.config'
import { useRouter } from 'next/router'
// 主题组件
const BlogListScroll = dynamic(() => import('./components/BlogListScroll'), { ssr: false });
const BlogArchiveItem = dynamic(() => import('./components/BlogArchiveItem'), { ssr: false });
const ArticleLock = dynamic(() => import('./components/ArticleLock'), { ssr: false });
const ArticleInfo = dynamic(() => import('./components/ArticleInfo'), { ssr: false });
const Comment = dynamic(() => import('@/components/Comment'), { ssr: false });
const ArticleAround = dynamic(() => import('./components/ArticleAround'), { ssr: false });
const ShareBar = dynamic(() => import('@/components/ShareBar'), { ssr: false });
const TopBar = dynamic(() => import('./components/TopBar'), { ssr: false });
const Header = dynamic(() => import('./components/Header'), { ssr: false });
const NavBar = dynamic(() => import('./components/NavBar'), { ssr: false });
const SideBar = dynamic(() => import('./components/SideBar'), { ssr: false });
const JumpToTopButton = dynamic(() => import('./components/JumpToTopButton'), { ssr: false });
const Footer = dynamic(() => import('./components/Footer'), { ssr: false });
const SearchInput = dynamic(() => import('./components/SearchInput'), { ssr: false });
const WWAds = dynamic(() => import('@/components/WWAds'), { ssr: false });
const BlogListPage = dynamic(() => import('./components/BlogListPage'), { ssr: false })
// 主题全局状态
const ThemeGlobalSimple = createContext()
export const useSimpleGlobal = () => useContext(ThemeGlobalSimple)
/**
* 基础布局
*
* @param {*} props
* @returns
*/
const LayoutBase = props => {
const { children, slotTop } = props
const { onLoading, fullWidth } = useGlobal()
const searchModal = useRef(null)
return (
{siteConfig('SIMPLE_TOP_BAR', null, CONFIG) &&
}
{/* 顶部LOGO */}
{/* 导航栏 */}
{/* 主体 */}
{/* 搜索框 */}
)
}
/**
* 博客首页
* 首页就是列表
* @param {*} props
* @returns
*/
const LayoutIndex = props => {
return
}
/**
* 博客列表
* @param {*} props
* @returns
*/
const LayoutPostList = props => {
return (
<>
{siteConfig('POST_LIST_STYLE') === 'page' ? : }
>
)
}
/**
* 搜索页
* 也是博客列表
* @param {*} props
* @returns
*/
const LayoutSearch = props => {
const { keyword } = props
useEffect(() => {
if (isBrowser) {
replaceSearchResult({
doms: document.getElementById('posts-wrapper'),
search: keyword,
target: {
element: 'span',
className: 'text-red-500 border-b border-dashed'
}
})
}
}, [])
const slotTop = siteConfig('ALGOLIA_APP_ID') ? null :
return
}
/**
* 归档页
* @param {*} props
* @returns
*/
const LayoutArchive = props => {
const { archivePosts } = props
return (
<>
{Object.keys(archivePosts).map(archiveTitle => )}
>
)
}
/**
* 文章详情
* @param {*} props
* @returns
*/
const LayoutSlug = props => {
const { post, lock, validPassword, prev, next } = props
const { fullWidth } = useGlobal()
return (
<>
{lock && }
{/* 文章信息 */}
{/* 广告嵌入 */}
{/*
*/}
{/* Notion文章主体 */}
{!lock &&
}
{/* 分享 */}
{/* 广告嵌入 */}
{post?.type === 'Post' &&
}
{/* 评论区 */}
>
)
}
/**
* 404
* @param {*} props
* @returns
*/
const Layout404 = (props) => {
const { post } = props
const router = useRouter()
useEffect(() => {
// 404
if (!post) {
setTimeout(() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)
})
}
}
}, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
}
}, [post])
return <>
404 Not found.
>
}
/**
* 分类列表
* @param {*} props
* @returns
*/
const LayoutCategoryIndex = props => {
const { categoryOptions } = props
return (
<>
{categoryOptions?.map(category => {
return (
{category.name}({category.count})
)
})}
>
)
}
/**
* 标签列表
* @param {*} props
* @returns
*/
const LayoutTagIndex = (props) => {
const { tagOptions } = props
return (
<>
>
)
}
/**
* 根据路径 获取对应的layout
* @param {*} path
* @returns
*/
const getLayoutNameByPath = (path) => {
// 检查特殊处理的路径
if (LAYOUT_MAPPINGS[path]) {
return LAYOUT_MAPPINGS[path];
} else {
// 没有特殊处理的路径返回默认layout名称
return 'LayoutSlug';
}
}
export {
CONFIG as THEME_CONFIG,
LayoutBase,
LayoutIndex,
LayoutSearch,
LayoutArchive,
LayoutSlug,
Layout404,
LayoutCategoryIndex,
LayoutPostList,
LayoutTagIndex,
getLayoutNameByPath
}