import Comment from '@/components/Comment'
import LoadingCover from '@/components/LoadingCover'
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 Link from 'next/link'
import { useRouter } from 'next/router'
import { createContext, useContext, useEffect, useState } from 'react'
import Announcement from './components/Announcement'
import ArticleInfo from './components/ArticleInfo'
import { ArticleLock } from './components/ArticleLock'
import BannerFullWidth from './components/BannerFullWidth'
import Catalog from './components/Catalog'
import CategoryGroup from './components/CategoryGroup'
import CategoryItem from './components/CategoryItem'
import Footer from './components/Footer'
import Header from './components/Header'
import Hero from './components/Hero'
import PostBannerGroupByCategory from './components/PostBannerGroupByCategory'
import PostGroupArchive from './components/PostGroupArchive'
import PostGroupLatest from './components/PostGroupLatest'
import PostListPage from './components/PostListPage'
import PostListRecommend from './components/PostListRecommend'
import PostListScroll from './components/PostListScroll'
import PostSimpleListHorizontal from './components/PostListSimpleHorizontal'
import TagGroups from './components/TagGroups'
import TagItemMini from './components/TagItemMini'
import TocDrawer from './components/TocDrawer'
import TouchMeCard from './components/TouchMeCard'
import CONFIG from './config'
import { Style } from './style'
// 主题全局状态
const ThemeGlobalMagzine = createContext()
export const useMagzineGlobal = () => useContext(ThemeGlobalMagzine)
/**
* 基础布局
* 采用左右两侧布局,移动端使用顶部导航栏
* @returns {JSX.Element}
* @constructor
*/
const LayoutBase = props => {
const { children, notice, showInfoCard = true, post } = props
const { locale } = useGlobal()
const router = useRouter()
const [tocVisible, changeTocVisible] = useState(false)
const { onLoading, fullWidth } = useGlobal()
const [slotRight, setSlotRight] = useState(null)
return (
{/* CSS样式 */}
)
}
/**
* 首页
* 首页就是一个博客列表
* @param {*} props
* @returns
*/
const LayoutIndex = props => {
const { posts, categoryOptions, allNavPages, latestPosts } = props
// 最新文章 从第4个元素开始截取出4个
const newPosts = posts.slice(3, 7)
return (
{/* 首屏宣传区块 */}
{/* 最新文章区块 */}
{/* 文章分类陈列区 */}
{/* 文章推荐 */}
)
}
/**
* 博客列表
* @returns
*/
const LayoutPostList = props => {
// 当前筛选的分类或标签
const { category, tag } = props
return (
{/* 一个顶部条 */}
{category || tag}
{siteConfig('POST_LIST_STYLE') === 'page' ? (
) : (
)}
)
}
/**
* 文章详情
* @param {*} props
* @returns
*/
const LayoutSlug = props => {
const { post, recommendPosts, prev, next, lock, validPassword } = props
const { locale } = useGlobal()
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 && (
{/* 文章信息 */}
{/* 文章区块分为三列 */}
{/* Notion文章主体 */}
{/* 文章底部区域 */}
{/* 分享 */}
{/* 文章分类和标签信息 */}
{siteConfig('MAGZINE_POST_DETAIL_CATEGORY') &&
post?.category && (
)}
{siteConfig('MAGZINE_POST_DETAIL_TAG') &&
post?.tagItems?.map(tag => (
))}
{/* 评论区 */}
{/* meta信息 */}
{/*
{post?.publishDay}
*/}
{post?.lastEditedDay}
{/* 最新文章区块 */}
{/* 文章分类区块 */}
{/* 底部留白 */}
{/* 移动端目录 */}
)}
{/* 广告醒图 */}
{/* 最新文章区块 */}
>
)
}
/**
* 搜索
* @param {*} props
* @returns
*/
const LayoutSearch = props => {
const { locale } = useGlobal()
const { keyword } = props
const router = useRouter()
const currentSearch = keyword || router?.query?.s
useEffect(() => {
if (isBrowser) {
replaceSearchResult({
doms: document.getElementById('posts-wrapper'),
search: keyword,
target: {
element: 'span',
className: 'text-red-500 border-b border-dashed'
}
})
}
}, [])
return (
{/* 搜索导航栏 */}
{locale.NAV.SEARCH}
{!currentSearch && (
<>
>
)}
{/* 文章列表 */}
{currentSearch && (
{siteConfig('POST_LIST_STYLE') === 'page' ? (
) : (
)}
)}
)
}
/**
* 归档
* @param {*} props
* @returns
*/
const LayoutArchive = props => {
const { archivePosts } = props
return (
<>
{Object.keys(archivePosts)?.map(archiveTitle => (
))}
>
)
}
/**
* 404
* @param {*} props
* @returns
*/
const Layout404 = props => {
return (
<>
404 Not found.
>
)
}
/**
* 分类列表
* @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 (
{/* */}
{locale.COMMON.TAGS}:
)
}
export {
Layout404,
LayoutArchive,
LayoutBase,
LayoutCategoryIndex,
LayoutIndex,
LayoutPostList,
LayoutSearch,
LayoutSlug,
LayoutTagIndex,
CONFIG as THEME_CONFIG
}