'use client'
/**
* # NAV 主题说明
* 主题开发者 [emengweb](https://github.com/emengweb)
* 开启方式 在blog.config.js 将主题配置为 `NAV`
*/
import Comment from '@/components/Comment'
import { AdSlot } from '@/components/GoogleAdsense'
import Live2D from '@/components/Live2D'
import NotionIcon from '@/components/NotionIcon'
import NotionPage from '@/components/NotionPage'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { isBrowser } from '@/lib/utils'
import { Transition } from '@headlessui/react'
import dynamic from 'next/dynamic'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { createContext, useContext, useEffect, useState } from 'react'
import Announcement from './components/Announcement'
import { ArticleLock } from './components/ArticleLock'
import BlogArchiveItem from './components/BlogArchiveItem'
import BlogPostCard from './components/BlogPostCard'
import BlogPostListAll from './components/BlogPostListAll'
import CategoryItem from './components/CategoryItem'
import FloatButtonCatalog from './components/FloatButtonCatalog'
import Footer from './components/Footer'
import JumpToTopButton from './components/JumpToTopButton'
import LogoBar from './components/LogoBar'
import { MenuItem } from './components/MenuItem'
import PageNavDrawer from './components/PageNavDrawer'
import TagItemMini from './components/TagItemMini'
import TocDrawer from './components/TocDrawer'
import TopNavBar from './components/TopNavBar'
import CONFIG from './config'
import { Style } from './style'
const WWAds = dynamic(() => import('@/components/WWAds'), { ssr: false })
// 主题全局变量
const ThemeGlobalNav = createContext()
export const useNavGlobal = () => useContext(ThemeGlobalNav)
/**
* 基础布局
* 采用左右两侧布局,移动端使用顶部导航栏
* @returns {JSX.Element}
* @constructor
*/
const LayoutBase = props => {
const {
customMenu,
children,
post,
allNavPages,
categoryOptions,
slotLeft,
slotTop
} = props
const { onLoading } = useGlobal()
const [tocVisible, changeTocVisible] = useState(false)
const [pageNavVisible, changePageNavVisible] = useState(false)
const [filteredNavPages, setFilteredNavPages] = useState(allNavPages)
const showTocButton = post?.toc?.length > 1
useEffect(() => {
setFilteredNavPages(allNavPages)
}, [post])
let links = customMenu
// 默认使用自定义菜单,否则将遍历所有的category生成菜单
if (!siteConfig('NAV_USE_CUSTOM_MENU', null, CONFIG)) {
links =
categoryOptions &&
categoryOptions?.map(c => {
return {
id: c.name,
title: `# ${c.name}`,
href: `/category/${c.name}`,
show: true
}
})
}
return (
{/* 样式 */}
{/* 主题样式根基 */}
{/* 端顶部导航栏 */}
{/* 左右布局区块 */}
{/* 左侧推拉抽屉 */}
{/* 图标Logo */}
{/* 嵌入 */}
{slotLeft}
{/* 显示菜单 */}
{links &&
links?.map((link, index) => (
))}
{/* 页脚站点信息 */}
{/* 右侧主要内容区块 */}
{slotTop}
{/* 广告植入 */}
{children}
{/* Google广告 */}
{/* 回顶按钮 */}
{/* 底部 */}
{/* 移动端悬浮目录按钮 */}
{showTocButton && !tocVisible && (
)}
{/* 移动端导航抽屉 */}
)
}
/**
* 首页
* @param {*} props
* @returns 此主题首页就是列表
*/
const LayoutIndex = props => {
return
}
/**
* 首页列表
* @param {*} props
* @returns
*/
const LayoutPostListIndex = props => {
// const { customMenu, children, post, allNavPages, categoryOptions, slotLeft, slotRight, slotTop, meta } = props
// const [filteredNavPages, setFilteredNavPages] = useState(allNavPages)
return (
<>
>
)
}
/**
* 文章列表
* @param {*} props
* @returns
*/
const LayoutPostList = props => {
const { posts } = props
// 顶部如果是按照分类或标签查看文章列表,列表顶部嵌入一个横幅
// 如果是搜索,则列表顶部嵌入 搜索框
return (
<>
{posts?.map(post => (
))}
>
)
}
/**
* 文章详情
* @param {*} props
* @returns
*/
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
setTimeout(
() => {
if (isBrowser) {
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)
})
}
}
},
waiting404
)
}
}, [post])
return (
<>
{/* 文章锁 */}
{lock && }
{!lock && (
{/* title */}
{siteConfig('POST_TITLE_ICON') && (
)}
{post?.title}
{/* Notion文章主体 */}
{post && (
{/* 分享 */}
{/* */}
{/* 文章分类和标签信息 */}
{CONFIG.POST_DETAIL_CATEGORY && post?.category && (
)}
{CONFIG.POST_DETAIL_TAG &&
post?.tagItems?.map(tag => (
))}
{/* 上一篇、下一篇文章 */}
{/* {post?.type === 'Post' && } */}
)}
)}
>
)
}
/**
* 没有搜索
* 全靠页面导航
* @param {*} props
* @returns
*/
const LayoutSearch = props => {
return <>>
}
/**
* 归档页面基本不会用到
* 全靠页面导航
* @param {*} props
* @returns
*/
const LayoutArchive = props => {
const { archivePosts } = props
return (
<>
{Object.keys(archivePosts).map(archiveTitle => (
))}
>
)
}
/**
* 404
* @param {*} props
* @returns
*/
const Layout404 = props => {
const router = useRouter()
useEffect(() => {
// 延时3秒如果加载失败就返回首页
setTimeout(() => {
const article = isBrowser && document.getElementById('article-wrapper')
if (!article) {
router.push('/').then(() => {
// console.log('找不到页面', router.asPath)
})
}
}, 3000)
}, [])
return <>
>
}
/**
* 分类列表
*/
const LayoutCategoryIndex = props => {
const { categoryOptions } = props
const { locale } = useGlobal()
return (
<>
{locale.COMMON.CATEGORY}:
{categoryOptions?.map(category => {
return (
{category.name}({category.count})
)
})}
>
)
}
/**
* 标签列表
*/
const LayoutTagIndex = props => {
return <>>
}
export {
Layout404,
LayoutArchive,
LayoutBase,
LayoutCategoryIndex,
LayoutIndex,
LayoutPostList,
LayoutSearch,
LayoutSlug,
LayoutTagIndex,
CONFIG as THEME_CONFIG
}