import Comment from '@/components/Comment'
import { AdSlot } from '@/components/GoogleAdsense'
import replaceSearchResult from '@/components/Mark'
import NotionPage from '@/components/NotionPage'
import ShareBar from '@/components/ShareBar'
import { siteConfig } from '@/lib/config'
import { deepClone, isBrowser } from '@/lib/utils'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { createContext, useContext, useEffect, useRef, useState } from 'react'
import Announcement from './components/Announcement'
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 { Footer } from './components/Footer'
import Header from './components/Header'
import NavBar from './components/NavBar'
import SearchNavBar from './components/SearchNavBar'
import SideBarContent from './components/SideBarContent'
import SideBarDrawer from './components/SideBarDrawer'
import CONFIG from './config'
import { Style } from './style'
// const AlgoliaSearchModal = dynamic(() => import('@/components/AlgoliaSearchModal'), { ssr: false })
// 主题全局状态
const ThemeGlobalGame = createContext()
export const useGameGlobal = () => useContext(ThemeGlobalGame)
/**
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
* @returns {JSX.Element}
* @constructor
*/
const LayoutBase = props => {
const { allNavPages, children } = props
// const fullWidth = post?.fullWidth ?? false
// const { onLoading } = useGlobal()
const searchModal = useRef(null)
// 在列表中进行实时过滤
const [filterKey, setFilterKey] = useState('')
const [filterGames, setFilterGames] = useState(deepClone(allNavPages?.filter(item => item.recommend)))
const [recentGames, setRecentGames] = useState([])
const [sideBarVisible, setSideBarVisible] = useState(false)
useEffect(() => {
setRecentGames(localStorage.getItem('recent_games') ? JSON.parse(localStorage.getItem('recent_games')) : [])
}, [])
return (
{/* 左右布局 */}
{/* 左侧 */}
{/* 右侧 */}
{children}
{
setSideBarVisible(false)
}}>
)
}
/**
* 首页
* 首页是个博客列表,加上顶部嵌入一个公告
* @param {*} props
* @returns
*/
const LayoutIndex = props => {
return } />
}
/**
* 博客列表
* @param {*} props
* @returns
*/
const LayoutPostList = props => {
const { posts, topSlot, tag } = props
const { filterKey } = useGameGlobal()
let filteredBlogPosts = []
if (filterKey && posts) {
filteredBlogPosts = posts.filter(post => {
const tagContent = post?.tags ? post?.tags.join(' ') : ''
const searchContent = post.title + post.summary + tagContent
return searchContent.toLowerCase().includes(filterKey.toLowerCase())
})
} else {
filteredBlogPosts = deepClone(posts)
}
return (
<>
{topSlot}
{tag && }
{siteConfig('POST_LIST_STYLE') === 'page' ? (
) : (
)}
>
)
}
/**
* 搜索
* 页面是博客列表,上方嵌入一个搜索引导条
* @param {*} props
* @returns
*/
const LayoutSearch = props => {
const { keyword, posts } = props
useEffect(() => {
if (isBrowser) {
replaceSearchResult({
doms: document.getElementById('posts-wrapper'),
search: keyword,
target: {
element: 'span',
className: 'text-red-500 border-b border-dashed'
}
})
}
}, [])
// 在列表中进行实时过滤
const { filterKey } = useGameGlobal()
let filteredBlogPosts = []
if (filterKey && posts) {
filteredBlogPosts = posts.filter(post => {
const tagContent = post?.tags ? post?.tags.join(' ') : ''
const searchContent = post.title + post.summary + tagContent
return searchContent.toLowerCase().includes(filterKey.toLowerCase())
})
} else {
filteredBlogPosts = deepClone(posts)
}
return (
<>
{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
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 (
<>
{lock && }
{!lock && (
)}
>
)
}
/**
* 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
}