import CONFIG from './config'
import { createContext, useContext, useEffect, useRef } from 'react'
import Footer from './components/Footer'
import SideRight from './components/SideRight'
import TopNav from './components/TopNav'
import { useGlobal } from '@/lib/global'
import { isBrowser } from '@/lib/utils'
import BlogPostListPage from './components/BlogPostListPage'
import BlogPostListScroll from './components/BlogPostListScroll'
import Hero from './components/Hero'
import { useRouter } from 'next/router'
import Card from './components/Card'
import RightFloatArea from './components/RightFloatArea'
import SearchNav from './components/SearchNav'
import BlogPostArchive from './components/BlogPostArchive'
import { ArticleLock } from './components/ArticleLock'
import PostHeader from './components/PostHeader'
import JumpToCommentButton from './components/JumpToCommentButton'
import TocDrawer from './components/TocDrawer'
import TocDrawerButton from './components/TocDrawerButton'
import Comment from '@/components/Comment'
import NotionPage from '@/components/NotionPage'
import ArticleAdjacent from './components/ArticleAdjacent'
import ArticleCopyright from './components/ArticleCopyright'
import ArticleRecommend from './components/ArticleRecommend'
import ShareBar from '@/components/ShareBar'
import TagItemMini from './components/TagItemMini'
import Link from 'next/link'
import SlotBar from './components/SlotBar'
import { Transition } from '@headlessui/react'
import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
import { siteConfig } from '@/lib/config'
import AlgoliaSearchModal from '@/components/AlgoliaSearchModal'
// 主题全局状态
const ThemeGlobalHexo = createContext()
export const useHexoGlobal = () => useContext(ThemeGlobalHexo)
/**
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
* @param props
* @returns {JSX.Element}
* @constructor
*/
const LayoutBase = props => {
const { post, children, slotTop, className } = props
const { onLoading, fullWidth } = useGlobal()
const router = useRouter()
const headerSlot = post
?
: (router.route === '/' && siteConfig('HEXO_HOME_BANNER_ENABLE', null, CONFIG)
?
: null)
const drawerRight = useRef(null)
const tocRef = isBrowser ? document.getElementById('article-wrapper') : null
const floatSlot = <>
{post?.toc?.length > 1 &&
{
drawerRight?.current?.handleSwitchVisible()
}}
/>
}
>
// Algolia搜索框
const searchModal = useRef(null)
return (
{/* 顶部导航 */}
{/* 顶部嵌入 */}
{headerSlot}
{/* 主区块 */}
{/* 主区上部嵌入 */}
{slotTop}
{children}
{/* 右侧栏 */}
{/* 悬浮菜单 */}
{/* 全文搜索 */}
{/* 页脚 */}
)
}
/**
* 首页
* 是一个博客列表,嵌入一个Hero大图
* @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
const router = useRouter()
const currentSearch = keyword || router?.query?.s
useEffect(() => {
if (currentSearch) {
replaceSearchResult({
doms: document.getElementsByClassName('replace'),
search: keyword,
target: {
element: 'span',
className: 'text-red-500 border-b border-dashed'
}
})
}
})
return (
{!currentSearch
?
:
{siteConfig('POST_LIST_STYLE') === 'page' ? : }
}
)
}
/**
* 归档
* @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 } = props
return (
<>
{lock &&
}
{!lock &&
{/* Notion文章主体 */}
{/* 分享 */}
{post?.type === 'Post' && <>
>}
{/* 评论互动 */}
}
>
)
}
/**
* 404
* @param {*} props
* @returns
*/
const Layout404 = props => {
const router = useRouter()
useEffect(() => {
// 延时3秒如果加载失败就返回首页
setTimeout(() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
if (!article) {
router.push('/').then(() => {
// console.log('找不到页面', router.asPath)
})
}
}
}, 3000)
})
return (
<>
>
)
}
/**
* 分类列表
* @param {*} props
* @returns
*/
const LayoutCategoryIndex = props => {
const { categoryOptions } = props
const { locale } = useGlobal()
return (
{locale.COMMON.CATEGORY}:
{categoryOptions?.map(category => {
return (
{category.name}({category.count})
)
})}
)
}
/**
* 标签列表
* @param {*} props
* @returns
*/
const LayoutTagIndex = props => {
const { tagOptions } = props
const { locale } = useGlobal()
return (
)
}
export {
CONFIG as THEME_CONFIG,
LayoutBase,
LayoutIndex,
LayoutSearch,
LayoutArchive,
LayoutSlug,
Layout404,
LayoutCategoryIndex,
LayoutPostList,
LayoutTagIndex
}