/* eslint-disable @next/next/no-img-element */
import Comment from '@/components/Comment'
import { AdSlot } from '@/components/GoogleAdsense'
import replaceSearchResult from '@/components/Mark'
import NotionPage from '@/components/NotionPage'
import { PWA as initialPWA } from '@/components/PWA'
import ShareBar from '@/components/ShareBar'
import { siteConfig } from '@/lib/config'
import { loadWowJS } from '@/lib/plugins/wow'
import { deepClone, isBrowser, shuffleArray } from '@/lib/utils'
import Link from 'next/link'
import { createContext, useContext, useEffect, useRef, useState } from 'react'
import Announcement from './components/Announcement'
import { ArticleLock } from './components/ArticleLock'
import BlogArchiveItem from './components/BlogArchiveItem'
import { BlogListPage } from './components/BlogListPage'
import { BlogListScroll } from './components/BlogListScroll'
import BlogPostBar from './components/BlogPostBar'
import { Footer } from './components/Footer'
import GameEmbed from './components/GameEmbed'
import { GameListIndexCombine } from './components/GameListIndexCombine'
import { GameListRelate } from './components/GameListRealate'
import { GameListRecent } from './components/GameListRecent'
import GroupCategory from './components/GroupCategory'
import GroupTag from './components/GroupTag'
import Header from './components/Header'
import { MenuList } from './components/MenuList'
import PostInfo from './components/PostInfo'
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, siteInfo } = props
const searchModal = useRef(null)
// 在列表中进行实时过滤
const [filterKey, setFilterKey] = useState('')
const [filterGames, setFilterGames] = useState(
deepClone(
allNavPages?.filter(item =>
item.tags?.some(
t => t === siteConfig('GAME_RECOMMEND_TAG', 'Recommend', CONFIG)
)
)
)
)
const [recentGames, setRecentGames] = useState([])
const [sideBarVisible, setSideBarVisible] = useState(false)
useEffect(() => {
loadWowJS()
}, [])
return (
{/* 左右布局 */}
{/* PC端左侧 */}
{/* 抬头logo等 */}
{/* 菜单栏 */}
{/* 左侧广告栏目 */}
{/* 右侧 */}
{children}
{
setSideBarVisible(false)
}}>
)
}
/**
* 首页
* 首页是个博客列表,加上顶部嵌入一个公告
* @param {*} props
* @returns
*/
const LayoutIndex = props => {
const { tagOptions, currentTag, categoryOptions, currentCategory, siteInfo } =
props
return (
<>
{/* 首页移动端顶部导航 */}
{/* 最近游戏 */}
{/* 游戏列表 */}
{/* 广告 */}
{/* 主区域下方 导览 */}
{/* 标签汇总 */}
{/* 站点公告信息 */}
>
)
}
/**
* 博客列表
* @param {*} props
* @returns
*/
const LayoutPostList = props => {
const { posts } = 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 (
<>
{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 { setRecentGames } = useGameGlobal()
const { post, siteInfo, allNavPages, recommendPosts, lock, validPassword } =
props
const relateGames = recommendPosts
const randomGames = shuffleArray(deepClone(allNavPages))
// 初始化可安装应用
initialPWA(post, siteInfo)
useEffect(() => {
// 更新最新游戏
const recentGames = localStorage.getItem('recent_games')
? JSON.parse(localStorage.getItem('recent_games'))
: []
const existedIndex = recentGames.findIndex(item => item?.id === post?.id)
if (existedIndex === -1) {
recentGames.unshift(post) // 将游戏插入到数组头部
} else {
// 如果游戏已存在于数组中,将其移至数组头部
const existingGame = recentGames.splice(existedIndex, 1)[0]
recentGames.unshift(existingGame)
}
localStorage.setItem('recent_games', JSON.stringify(recentGames))
setRecentGames(recentGames)
}, [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 (
<>
{tagOptions.map(tag => {
return (
{' '}
{tag.name + (tag.count ? `(${tag.count})` : '')}{' '}
)
})}
>
)
}
export {
Layout404,
LayoutArchive,
LayoutBase,
LayoutCategoryIndex,
LayoutIndex,
LayoutPostList,
LayoutSearch,
LayoutSlug,
LayoutTagIndex,
CONFIG as THEME_CONFIG
}