'use client' /** * # NAV 主题说明 * 主题开发者 [emengweb](https://github.com/emengweb) * 开启方式 在blog.config.js 将主题配置为 `NAV` */ import CONFIG from './config' import { useEffect, useState, createContext, useContext } from 'react' import Footer from './components/Footer' import TopNavBar from './components/TopNavBar' import { useGlobal } from '@/lib/global' import BLOG from '@/blog.config' import Announcement from './components/Announcement' import PageNavDrawer from './components/PageNavDrawer' import FloatTocButton from './components/FloatTocButton' import { AdSlot } from '@/components/GoogleAdsense' import JumpToTopButton from './components/JumpToTopButton' import CategoryItem from './components/CategoryItem' import TagItemMini from './components/TagItemMini' import Comment from '@/components/Comment' import TocDrawer from './components/TocDrawer' import NotionPage from '@/components/NotionPage' import { ArticleLock } from './components/ArticleLock' import { Transition } from '@headlessui/react' import { Style } from './style' import CommonHead from '@/components/CommonHead' import BlogArchiveItem from './components/BlogArchiveItem' import BlogPostListAll from './components/BlogPostListAll' import BlogPostCard from './components/BlogPostCard' import Link from 'next/link' import dynamic from 'next/dynamic' import { MenuItem } from './components/MenuItem' 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, meta } = 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 (!CONFIG.USE_CUSTOM_MENU) { links = categoryOptions && categoryOptions?.map(c => { return { id: c.name, title: `# ${c.name}`, to: `/category/${c.name}`, show: true } }) } return ( {/* HEAD */} {/* 样式 */} {/* 主题样式根基 */} {/* 端顶部导航栏 */} {/* 左右布局区块 */} {/* 左侧推拉抽屉 */} {/* 嵌入 */} {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 return ( {/* 文章锁 */} {lock && } {!lock && {/* title */} {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 */ const Layout404 = props => { return 404 Not found. } /** * 分类列表 */ const LayoutCategoryIndex = (props) => { const { categoryOptions } = props const { locale } = useGlobal() return {locale.COMMON.CATEGORY}: {categoryOptions?.map(category => { return ( {category.name}({category.count}) ) })} } /** * 标签列表 */ const LayoutTagIndex = (props) => { const { tagOptions } = props const { locale } = useGlobal() return {locale.COMMON.TAGS}: {tagOptions?.map(tag => { return ( ) })} } export { CONFIG as THEME_CONFIG, LayoutIndex, LayoutSearch, LayoutArchive, LayoutSlug, Layout404, LayoutCategoryIndex, LayoutPostList, LayoutTagIndex }