import Comment from '@/components/Comment'
import { Draggable } from '@/components/Draggable'
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, 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 FullScreen from './components/FullScreen'
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 } = 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.tags?.some(
t => t === siteConfig('GAME_RECOMMEND_TAG', 'Recommend', CONFIG)
)
)
)
)
const [recentGames, setRecentGames] = useState([])
const [sideBarVisible, setSideBarVisible] = useState(false)
useEffect(() => {
setRecentGames(
localStorage.getItem('recent_games')
? JSON.parse(localStorage.getItem('recent_games'))
: []
)
}, [])
return (
{/* 左右布局 */}
{/* PC端左侧 */}
{/* 抬头logo等 */}
{/* 菜单栏 */}
{/* 左侧广告栏目 */}
{/* 右侧 */}
{children}
{
setSideBarVisible(false)
}}>
)
}
/**
* 首页
* 首页是个博客列表,加上顶部嵌入一个公告
* @param {*} props
* @returns
*/
const LayoutIndex = props => {
const { tagOptions, currentTag, categoryOptions, currentCategory } = 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 { post, allNavPages, recommendPosts, lock, validPassword } = props
const game = deepClone(post)
const [loading, setLoading] = useState(false)
// const [url, setUrl] = useState(game?.ext?.href)
const relateGames = recommendPosts
const randomGames = shuffleArray(deepClone(allNavPages))
// 将当前游戏加入到最近游玩
useEffect(() => {
// 更新最新游戏
const recentGames = localStorage.getItem('recent_games')
? JSON.parse(localStorage.getItem('recent_games'))
: []
const existedIndex = recentGames.findIndex(item => item?.id === game?.id)
if (existedIndex === -1) {
recentGames.unshift(game) // 将游戏插入到数组头部
} else {
// 如果游戏已存在于数组中,将其移至数组头部
const existingGame = recentGames.splice(existedIndex, 1)[0]
recentGames.unshift(existingGame)
}
localStorage.setItem('recent_games', JSON.stringify(recentGames))
const iframe = document.getElementById('game-wrapper')
// 定义一个函数来处理iframe加载成功事件
function iframeLoaded() {
if (game) {
setLoading(false)
}
}
// 绑定加载事件
if (iframe?.attachEvent) {
iframe?.attachEvent('onload', iframeLoaded)
} else {
if (iframe) iframe.onload = iframeLoaded
}
// 更改iFrame的title
if (
document
?.getElementById('game-wrapper')
?.contentDocument.querySelector('title')?.textContent
) {
document
.getElementById('game-wrapper')
.contentDocument.querySelector('title').textContent = `${
game?.title || ''
} - Play ${game?.title || ''} on ${siteConfig('TITLE')}`
}
}, [game])
return (
<>
{lock && }
{!lock && (
{/* 游戏区域 */}
{/* 移动端返回主页按钮 */}
{' '}
{
document.querySelector('.game-info').scrollIntoView({
behavior: 'smooth',
block: 'end',
inline: 'nearest'
})
}}>
G
{/* 游戏区 */}
{/* Loading遮罩 */}
{loading && (
{siteConfig('TITLE')}
{siteConfig('DESCRIPTION')}
{/* 游戏封面图 */}
{/* eslint-disable-next-line @next/next/no-img-element */}
{game?.img && (

)}
)}
{/* 游戏窗口装饰器 */}
{game && !loading && (
{/* 加入全屏按钮 */}
)}
{/* 游戏资讯 */}
{/* 关联游戏 */}
{game && (
)}
{/* 其它游戏列表 */}
)}
>
)
}
/**
* 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
}