import CONFIG from './config'
import CommonHead from '@/components/CommonHead'
import { useEffect, useRef } from 'react'
import Footer from './components/Footer'
// import SideRight from './components/SideRight'
import { useGlobal } from '@/lib/global'
import { isBrowser, scanAndConvertToLinks } from '@/lib/utils'
import BlogPostListPage from './components/BlogPostListPage'
import BlogPostListScroll from './components/BlogPostListScroll'
import Hero from './components/Hero'
import { useRouter } from 'next/router'
import Card from './components/Card'
import RightFloatArea from './components/RightFloatArea'
import SearchNav from './components/SearchNav'
import BlogPostArchive from './components/BlogPostArchive'
import { ArticleLock } from './components/ArticleLock'
import PostHeader from './components/PostHeader'
import JumpToCommentButton from './components/JumpToCommentButton'
import TocDrawer from './components/TocDrawer'
import TocDrawerButton from './components/TocDrawerButton'
import NotionPage from '@/components/NotionPage'
import TagItemMini from './components/TagItemMini'
import Link from 'next/link'
import SlotBar from './components/SlotBar'
import { Transition } from '@headlessui/react'
import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
import { siteConfig } from '@/lib/config'
import TopNavBar from './components/TopNavBar'
import ProductCenter from './components/ProductCenter'
import LazyImage from '@/components/LazyImage'
import ProductCategories from './components/ProductCategories'
/**
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
* @param props
* @returns {JSX.Element}
* @constructor
*/
const LayoutBase = props => {
const { children, headerSlot, floatSlot, slotTop, slotRight, meta, className } = props
const { onLoading } = useGlobal()
// 查找页面上的 链接,并便成为可点击
useEffect(() => {
scanAndConvertToLinks(document.getElementById('theme-commerce'))
})
return (
{/* 网页SEO */}
{/* 顶部导航 */}
{/* 顶部嵌入 */}
{headerSlot}
{/* 主区块 */}
{/* 主区上部嵌入 */}
{slotTop}
{children}
{slotRight}
{/* 悬浮菜单 */}
{/* 页脚 */}
)
}
/**
* 首页
* 是一个博客列表,嵌入一个Hero大图
* @param {*} props
* @returns
*/
const LayoutIndex = (props) => {
// 首页Banner条
const headerSlot = CONFIG.HOME_BANNER_ENABLE &&
const { notice } = props
return
{/* 产品中心 */}
{/* 企业介绍 + 联系 */}
{notice &&
{siteConfig('TEXT_HOME_ABOUT_US', notice.title)}
}
{/* 铺开导航菜单 */}
}
/**
* 博客列表
* @param {*} props
* @returns
*/
const LayoutPostList = (props) => {
const slotRight =
return
{siteConfig('POST_LIST_STYLE') === 'page' ? : }
}
/**
* 搜索
* @param {*} props
* @returns
*/
const LayoutSearch = props => {
const { keyword } = props
const router = useRouter()
const currentSearch = keyword || router?.query?.s
useEffect(() => {
if (currentSearch) {
replaceSearchResult({
doms: document.getElementsByClassName('replace'),
search: keyword,
target: {
element: 'span',
className: 'text-red-500 border-b border-dashed'
}
})
}
})
return (
{!currentSearch
?
: {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 drawerRight = useRef(null)
const targetRef = isBrowser ? document.getElementById('article-wrapper') : null
const headerImage = post?.pageCover ? post.pageCover : siteConfig('HOME_BANNER_IMAGE')
const floatSlot = <>
{post?.toc?.length > 1 &&
{
drawerRight?.current?.handleSwitchVisible()
}}
/>
}
>
return (
} showCategory={false} showTag={false} floatSlot={floatSlot} >
{lock &&
}
{!lock &&
{/* 预览区块 */}
{post?.title}
{post?.summary}
{/* Notion文章主体 */}
}
)
}
/**
* 404
* @param {*} props
* @returns
*/
const Layout404 = props => {
const router = useRouter()
useEffect(() => {
// 延时3秒如果加载失败就返回首页
setTimeout(() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
if (!article) {
router.push('/').then(() => {
// console.log('找不到页面', router.asPath)
})
}
}
}, 3000)
})
return (
)
}
/**
* 分类列表
* @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 {
CONFIG as THEME_CONFIG,
LayoutIndex,
LayoutSearch,
LayoutArchive,
LayoutSlug,
Layout404,
LayoutCategoryIndex,
LayoutPostList,
LayoutTagIndex
}