import AlgoliaSearchModal from '@/components/AlgoliaSearchModal'
import Comment from '@/components/Comment'
import { AdSlot } from '@/components/GoogleAdsense'
import LoadingCover from '@/components/LoadingCover'
import replaceSearchResult from '@/components/Mark'
import NotionPage from '@/components/NotionPage'
import ShareBar from '@/components/ShareBar'
import WWAds from '@/components/WWAds'
import DashboardBody from '@/components/ui/dashboard/DashboardBody'
import DashboardHeader from '@/components/ui/dashboard/DashboardHeader'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { isBrowser } from '@/lib/utils'
import { SignIn, SignUp } from '@clerk/nextjs'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { createContext, useContext, useEffect, useRef, useState } from 'react'
import ArticleInfo from './components/ArticleInfo'
import { ArticleLock } from './components/ArticleLock'
import BannerFullWidth from './components/BannerFullWidth'
import CTA from './components/CTA'
import Catalog from './components/Catalog'
import CatalogFloat from './components/CatalogFloat'
import CategoryGroup from './components/CategoryGroup'
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 PostNavAround from './components/PostNavAround'
import TagGroups from './components/TagGroups'
import TagItemMini from './components/TagItemMini'
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 } = props
const [tocVisible, changeTocVisible] = useState(false)
const searchModal = useRef(null)
return (
{/* CSS样式 */}
{/* 主区 */}
{/* 全局Loading */}
{/* 全局搜索遮罩 */}
)
}
/**
* 首页
* 首页就是一个博客列表
* @param {*} props
* @returns
*/
const LayoutIndex = props => {
const { posts } = props
// 最新文章 从第4个元素开始截取出4个
const newPosts = posts.slice(3, 7)
return (
{/* 首屏宣传区块 */}
{/* 最新文章区块 */}
{/* 文章分类陈列区 */}
{/* 文章推荐 */}
{/* 行动呼吁 */}
)
}
/**
* 博客列表
* @returns
*/
const LayoutPostList = props => {
// 当前筛选的分类或标签
const { category, tag, NOTION_CONFIG } = props
return (
{/* 一个顶部条 */}
{category || tag}
{siteConfig('POST_LIST_STYLE', 'page', NOTION_CONFIG) === 'page' ? (
) : (
)}
)
}
/**
* 文章详情
* @param {*} props
* @returns
*/
const LayoutSlug = props => {
const { post, recommendPosts, prev, next, lock, validPassword } = props
const { locale } = useGlobal()
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post && router?.route?.indexOf('/[prefix]') === 0) {
setTimeout(() => {
if (isBrowser) {
const article = document.querySelector(
'#article-wrapper #notion-article'
)
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)
})
}
}
}, waiting404)
}
}, [router])
return (
<>
{/* 广告位 */}
{/* 文章锁 */}
{lock &&
}
{!lock && (
{post && (
<>
{/* 文章信息 */}
{/* 文章区块分为三列 */}
{/* Notion文章主体 */}
{/* 文章底部区域 */}
{siteConfig('MAGZINE_POST_DETAIL_TAG') &&
post?.tagItems?.map(tag => (
))}
{/* 分享 */}
{/* 上一篇下一篇 */}
{/* 评论区 */}
{/* meta信息 */}
{/*
{post?.publishDay}
*/}
{post?.lastEditedDay}
{/* 最新文章区块 */}
{/* Adsense */}
{/* 留白 */}
{/* 文章分类区块 */}
{/* 底部留白 */}
{/* 移动端目录 */}
>
)}
{!post && (
Loading...
)}
)}
{/* 广告醒图 */}
{/* 推荐关联文章 */}
{recommendPosts && recommendPosts.length > 0 && (
)}
>
)
}
/**
* 搜索
* @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}:
)
}
/**
* 登录页面
* @param {*} props
* @returns
*/
const LayoutSignIn = props => {
const { post } = props
const enableClerk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
return (
<>
{/* clerk预置表单 */}
{enableClerk && (
)}
>
)
}
/**
* 注册页面
* @param {*} props
* @returns
*/
const LayoutSignUp = props => {
const { post } = props
const enableClerk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
return (
<>
{/* clerk预置表单 */}
{enableClerk && (
)}
>
)
}
/**
* 仪表盘
* @param {*} props
* @returns
*/
const LayoutDashboard = props => {
const { post } = props
return (
<>
{/* 仪表盘 */}
>
)
}
export {
Layout404,
LayoutArchive,
LayoutBase,
LayoutCategoryIndex,
LayoutDashboard,
LayoutIndex,
LayoutPostList,
LayoutSearch,
LayoutSignIn,
LayoutSignUp,
LayoutSlug,
LayoutTagIndex,
CONFIG as THEME_CONFIG
}