import Comment from '@/components/Comment'
import replaceSearchResult from '@/components/Mark'
import NotionPage from '@/components/NotionPage'
import ShareBar from '@/components/ShareBar'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { isBrowser } from '@/lib/utils'
import { Transition } from '@headlessui/react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { createContext, useContext, useEffect, useState } from 'react'
import { ArticleFooter } from './components/ArticleFooter'
import { ArticleInfo } from './components/ArticleInfo'
import { ArticleLock } from './components/ArticleLock'
import BlogArchiveItem from './components/BlogArchiveItem'
import { BlogListPage } from './components/BlogListPage'
import { BlogListScroll } from './components/BlogListScroll'
import BottomNav from './components/BottomNav'
import Modal from './components/Modal'
import Header from './components/Nav'
import SearchNavBar from './components/SearchNavBar'
import CONFIG from './config'
import { Style } from './style'
// 主题全局状态
const ThemeGlobalPlog = createContext()
export const usePlogGlobal = () => useContext(ThemeGlobalPlog)
/**
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
* @returns {JSX.Element}
* @constructor
*/
const LayoutBase = props => {
const { children, topSlot } = props
const { onLoading } = useGlobal()
const [showModal, setShowModal] = useState(false)
const [modalContent, setModalContent] = useState(null)
// 页面切换关闭遮罩
const router = useRouter()
const closeModal = () => {
setShowModal(false)
}
useEffect(() => {
router.events.on('routeChangeComplete', closeModal)
return () => {
router.events.off('routeChangeComplete', closeModal)
}
}, [router.events])
return (
{/* 移动端顶部导航栏 */}
{/* 主区 */}
{/* 顶部插槽 */}
{topSlot}
{children}
{/* 弹出框 - 用于放大显示首页图片等作用 */}
{/* 桌面端底部导航栏 */}
)
}
/**
* 首页
* 首页是个博客列表,加上顶部嵌入一个公告
* @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'
}
})
}
}, [])
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 } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
setTimeout(
() => {
if (isBrowser) {
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)
})
}
}
},
waiting404
)
}
}, [post])
return (
<>
{lock && }
{!lock && post && (
)}
>
)
}
/**
* 404 页面
* @param {*} props
* @returns
*/
const Layout404 = props => {
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 (
<>
>
)
}
export {
Layout404,
LayoutArchive,
LayoutBase,
LayoutCategoryIndex,
LayoutIndex,
LayoutPostList,
LayoutSearch,
LayoutSlug,
LayoutTagIndex,
CONFIG as THEME_CONFIG
}