mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
theme-next-refactor
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
import { useRouter } from 'next/router'
|
||||
import LayoutBase from './LayoutBase'
|
||||
import { useEffect } from 'react'
|
||||
import { isBrowser } from '@/lib/utils'
|
||||
|
||||
export 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 <LayoutBase {...props}>
|
||||
<div
|
||||
className='md:-mt-20 text-black w-full h-screen text-center justify-center content-center items-center flex flex-col'>
|
||||
<div className='dark:text-gray-200'>
|
||||
<h2 className='inline-block border-r-2 border-gray-600 mr-2 px-3 py-2 align-top'><i className='mr-2 fas fa-spinner animate-spin' />404</h2>
|
||||
<div className='inline-block text-left h-32 leading-10 items-center'>
|
||||
<h2 className='m-0 p-0'>页面无法加载,即将返回首页</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</LayoutBase>
|
||||
}
|
||||
export default Layout404
|
||||
@@ -1,35 +0,0 @@
|
||||
import React, { useEffect } from 'react'
|
||||
import LayoutBase from './LayoutBase'
|
||||
import BlogPostArchive from './components/BlogPostArchive'
|
||||
|
||||
export const LayoutArchive = (props) => {
|
||||
const { archivePosts } = props
|
||||
|
||||
useEffect(() => {
|
||||
const anchor = window.location.hash
|
||||
if (anchor) {
|
||||
setTimeout(() => {
|
||||
const anchorElement = document.getElementById(anchor.substring(1))
|
||||
if (anchorElement) {
|
||||
anchorElement.scrollIntoView({ block: 'start', behavior: 'smooth' })
|
||||
}
|
||||
}, 300)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<LayoutBase {...props}>
|
||||
<div className="mb-10 pb-20 bg-white md:p-12 p-3 dark:bg-hexo-black-gray shadow-md min-h-full">
|
||||
{Object.keys(archivePosts).map(archiveTitle => (
|
||||
<BlogPostArchive
|
||||
key={archiveTitle}
|
||||
posts={archivePosts[archiveTitle]}
|
||||
archiveTitle={archiveTitle}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</LayoutBase>
|
||||
)
|
||||
}
|
||||
|
||||
export default LayoutArchive
|
||||
@@ -1,94 +0,0 @@
|
||||
import CommonHead from '@/components/CommonHead'
|
||||
import FloatDarkModeButton from './components/FloatDarkModeButton'
|
||||
import Footer from './components/Footer'
|
||||
import JumpToBottomButton from './components/JumpToBottomButton'
|
||||
import JumpToTopButton from './components/JumpToTopButton'
|
||||
import LoadingCover from './components/LoadingCover'
|
||||
import SideAreaLeft from './components/SideAreaLeft'
|
||||
import SideAreaRight from './components/SideAreaRight'
|
||||
import TopNav from './components/TopNav'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import CONFIG_NEXT from './config_next'
|
||||
import Live2D from '@/components/Live2D'
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
/**
|
||||
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
const LayoutBase = (props) => {
|
||||
const { children, headerSlot, meta, sideBarSlot, floatSlot, rightAreaSlot, siteInfo } = props
|
||||
const { onLoading } = useGlobal()
|
||||
const targetRef = useRef(null)
|
||||
const floatButtonGroup = useRef(null)
|
||||
const leftAreaSlot = <Live2D/>
|
||||
|
||||
const [showRightFloat, switchShow] = useState(false)
|
||||
const [percent, changePercent] = useState(0) // 页面阅读百分比
|
||||
|
||||
const scrollListener = () => {
|
||||
const targetRef = document.getElementById('wrapper')
|
||||
const clientHeight = targetRef?.clientHeight
|
||||
const scrollY = window.pageYOffset
|
||||
const fullHeight = clientHeight - window.outerHeight
|
||||
let per = parseFloat(((scrollY / fullHeight * 100)).toFixed(0))
|
||||
if (per > 100) per = 100
|
||||
const shouldShow = scrollY > 100 && per > 0
|
||||
|
||||
if (shouldShow !== showRightFloat) {
|
||||
switchShow(shouldShow)
|
||||
}
|
||||
changePercent(per)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
// facebook messenger 插件需要调整右下角悬浮按钮的高度
|
||||
const fb = document.getElementsByClassName('fb-customerchat')
|
||||
if (fb.length === 0) {
|
||||
floatButtonGroup?.current?.classList.replace('bottom-24', 'bottom-12')
|
||||
} else {
|
||||
floatButtonGroup?.current?.classList.replace('bottom-12', 'bottom-24')
|
||||
}
|
||||
|
||||
document.addEventListener('scroll', scrollListener)
|
||||
return () => document.removeEventListener('scroll', scrollListener)
|
||||
}, [showRightFloat])
|
||||
|
||||
return (<div id='theme-next'>
|
||||
|
||||
<CommonHead meta={meta} />
|
||||
|
||||
<TopNav slot={sideBarSlot} {...props}/>
|
||||
|
||||
<>{headerSlot}</>
|
||||
|
||||
<div className='h-0.5 w-full bg-gray-700 dark:bg-gray-600 hidden lg:block'/>
|
||||
|
||||
<main id='wrapper' className={(BLOG.LAYOUT_SIDEBAR_REVERSE ? 'flex-row-reverse' : '') + ' next relative flex justify-center flex-1 pb-12'}>
|
||||
{/* 左侧栏样式 */}
|
||||
<SideAreaLeft slot={leftAreaSlot} targetRef={targetRef} {...props}/>
|
||||
<section id='container-inner' className={`${CONFIG_NEXT.NAV_TYPE !== 'normal' ? 'mt-24' : ''} lg:max-w-3xl xl:max-w-4xl flex-grow md:mt-0 min-h-screen w-full relative z-10`} ref={targetRef}>
|
||||
{onLoading ? <LoadingCover/> : <> {children}</> }
|
||||
</section>
|
||||
{/* 右侧栏样式 */}
|
||||
{ CONFIG_NEXT.RIGHT_BAR && <SideAreaRight targetRef={targetRef} slot={rightAreaSlot} {...props}/> }
|
||||
</main>
|
||||
|
||||
{/* 右下角悬浮 */}
|
||||
<div ref={floatButtonGroup} className='right-8 bottom-12 lg:right-2 fixed justify-end z-20 font-sans'>
|
||||
<div className={(showRightFloat ? 'animate__animated ' : 'hidden') + ' animate__fadeInUp rounded-md glassmorphism justify-center duration-500 animate__faster flex space-x-2 items-center cursor-pointer '}>
|
||||
<JumpToTopButton percent={percent}/>
|
||||
<JumpToBottomButton />
|
||||
<FloatDarkModeButton/>
|
||||
{floatSlot}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Footer title={siteInfo?.title}/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default LayoutBase
|
||||
@@ -1,23 +0,0 @@
|
||||
import LayoutBase from './LayoutBase'
|
||||
import StickyBar from './components/StickyBar'
|
||||
import CategoryList from './components/CategoryList'
|
||||
import BlogPostListScroll from './components/BlogPostListScroll'
|
||||
import BlogPostListPage from './components/BlogPostListPage'
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
export const LayoutCategory = (props) => {
|
||||
const { category, categoryOptions } = props
|
||||
return <LayoutBase currentCategory={category} {...props}>
|
||||
<StickyBar>
|
||||
<CategoryList currentCategory={category} categoryOptions={categoryOptions} />
|
||||
</StickyBar>
|
||||
<div className='md:mt-8'>
|
||||
{BLOG.POST_LIST_STYLE !== 'page'
|
||||
? <BlogPostListScroll {...props} showSummary={true} />
|
||||
: <BlogPostListPage {...props} />
|
||||
}
|
||||
</div>
|
||||
</LayoutBase>
|
||||
}
|
||||
|
||||
export default LayoutCategory
|
||||
@@ -1,35 +0,0 @@
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import LayoutBase from './LayoutBase'
|
||||
import Link from 'next/link'
|
||||
|
||||
export const LayoutCategoryIndex = (props) => {
|
||||
const { allPosts, categoryOptions } = props
|
||||
const { locale } = useGlobal()
|
||||
return (
|
||||
<LayoutBase totalPosts={allPosts} {...props}>
|
||||
<div className='bg-white dark:bg-hexo-black-gray px-10 py-10 shadow h-full'>
|
||||
<div className='dark:text-gray-200 mb-5'>
|
||||
<i className='mr-4 fas faTh' />{locale.COMMON.CATEGORY}:
|
||||
</div>
|
||||
<div id='category-list' className='duration-200 flex flex-wrap'>
|
||||
{categoryOptions.map(category => {
|
||||
return (
|
||||
<Link
|
||||
key={category.name}
|
||||
href={`/category/${category.name}`}
|
||||
passHref
|
||||
legacyBehavior>
|
||||
<div
|
||||
className={'hover:text-black dark:hover:text-white dark:text-gray-300 dark:hover:bg-gray-600 px-5 cursor-pointer py-2 hover:bg-gray-100'}>
|
||||
<i className='mr-4 fas fa-folder' />{category.name}({category.count})
|
||||
</div>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</LayoutBase>
|
||||
)
|
||||
}
|
||||
|
||||
export default LayoutCategoryIndex
|
||||
@@ -1,26 +0,0 @@
|
||||
import LayoutBase from './LayoutBase'
|
||||
import Header from './components/Header'
|
||||
import LatestPostsGroup from './components/LatestPostsGroup'
|
||||
import Card from './components/Card'
|
||||
import BlogPostListScroll from './components/BlogPostListScroll'
|
||||
import BlogPostListPage from './components/BlogPostListPage'
|
||||
import CONFIG_NEXT from './config_next'
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
export const LayoutIndex = (props) => {
|
||||
const { latestPosts } = props
|
||||
const rightAreaSlot = CONFIG_NEXT.RIGHT_LATEST_POSTS && <Card><LatestPostsGroup latestPosts={latestPosts} /></Card>
|
||||
return <LayoutBase
|
||||
headerSlot={CONFIG_NEXT.HOME_BANNER && <Header {...props} />}
|
||||
sideBarSlot={<LatestPostsGroup posts={latestPosts} />}
|
||||
rightAreaSlot={rightAreaSlot}
|
||||
{...props}
|
||||
>
|
||||
{BLOG.POST_LIST_STYLE !== 'page'
|
||||
? <BlogPostListScroll {...props} showSummary={true} />
|
||||
: <BlogPostListPage {...props} />
|
||||
}
|
||||
</LayoutBase>
|
||||
}
|
||||
|
||||
export default LayoutIndex
|
||||
@@ -1,19 +0,0 @@
|
||||
import LayoutBase from './LayoutBase'
|
||||
import LatestPostsGroup from './components/LatestPostsGroup'
|
||||
import BlogPostListPage from './components/BlogPostListPage'
|
||||
import CONFIG_NEXT from './config_next'
|
||||
|
||||
export const LayoutPage = (props) => {
|
||||
const { latestPosts } = props
|
||||
return (
|
||||
<LayoutBase
|
||||
sideBarSlot={<LatestPostsGroup posts={latestPosts} />}
|
||||
rightAreaSlot={CONFIG_NEXT.RIGHT_LATEST_POSTS && <LatestPostsGroup posts={latestPosts} />}
|
||||
{...props}
|
||||
>
|
||||
<BlogPostListPage {...props}/>
|
||||
</LayoutBase>
|
||||
)
|
||||
}
|
||||
|
||||
export default LayoutPage
|
||||
@@ -1,41 +0,0 @@
|
||||
import LayoutBase from './LayoutBase'
|
||||
import StickyBar from './components/StickyBar'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import { isBrowser } from '@/lib/utils'
|
||||
import BlogPostListScroll from './components/BlogPostListScroll'
|
||||
import BlogPostListPage from './components/BlogPostListPage'
|
||||
import Mark from 'mark.js'
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
export const LayoutSearch = (props) => {
|
||||
const { locale } = useGlobal()
|
||||
const { posts, keyword } = props
|
||||
setTimeout(() => {
|
||||
const container = isBrowser() && document.getElementById('posts-wrapper')
|
||||
if (container && container.innerHTML) {
|
||||
const re = new RegExp(keyword, 'gim')
|
||||
const instance = new Mark(container)
|
||||
instance.markRegExp(re, {
|
||||
element: 'span',
|
||||
className: 'text-red-500 border-b border-dashed'
|
||||
})
|
||||
}
|
||||
}, 200)
|
||||
return (
|
||||
<LayoutBase {...props} >
|
||||
<StickyBar>
|
||||
<div className="p-4 dark:text-gray-200">
|
||||
<i className="mr-1 fas fa-search" />{' '}
|
||||
{posts?.length} {locale.COMMON.RESULT_OF_SEARCH}
|
||||
</div>
|
||||
</StickyBar>
|
||||
<div className="md:mt-5">
|
||||
{BLOG.POST_LIST_STYLE !== 'page'
|
||||
? <BlogPostListScroll {...props} showSummary={true} />
|
||||
: <BlogPostListPage {...props} />
|
||||
} </div>
|
||||
</LayoutBase>
|
||||
)
|
||||
}
|
||||
|
||||
export default LayoutSearch
|
||||
@@ -1,44 +0,0 @@
|
||||
import TocDrawerButton from './components/TocDrawerButton'
|
||||
import LayoutBase from './LayoutBase'
|
||||
import Card from './components/Card'
|
||||
import LatestPostsGroup from './components/LatestPostsGroup'
|
||||
import ArticleDetail from './components/ArticleDetail'
|
||||
import TocDrawer from './components/TocDrawer'
|
||||
import { useRef } from 'react'
|
||||
import CONFIG_NEXT from './config_next'
|
||||
import { ArticleLock } from './components/ArticleLock'
|
||||
import { isBrowser } from '@/lib/utils'
|
||||
|
||||
export const LayoutSlug = (props) => {
|
||||
const { post, latestPosts, lock, validPassword } = props
|
||||
const drawerRight = useRef(null)
|
||||
const targetRef = isBrowser() ? document.getElementById('article-wrapper') : null
|
||||
const floatSlot = post?.toc?.length > 1
|
||||
? <div className='block lg:hidden'><TocDrawerButton onClick={() => {
|
||||
drawerRight?.current?.handleSwitchVisible()
|
||||
}} /></div>
|
||||
: null
|
||||
|
||||
const rightAreaSlog = CONFIG_NEXT.RIGHT_LATEST_POSTS && <Card><LatestPostsGroup latestPosts={latestPosts} /></Card>
|
||||
|
||||
return (
|
||||
<LayoutBase
|
||||
{...props}
|
||||
floatSlot={floatSlot}
|
||||
rightAreaSlot={rightAreaSlog}
|
||||
>
|
||||
|
||||
{post && !lock && <ArticleDetail {...props} />}
|
||||
|
||||
{post && lock && <ArticleLock validPassword={validPassword} />}
|
||||
|
||||
{/* 悬浮目录按钮 */}
|
||||
{post && <div className='block lg:hidden'>
|
||||
<TocDrawer post={post} cRef={drawerRight} targetRef={targetRef} />
|
||||
</div>}
|
||||
|
||||
</LayoutBase>
|
||||
)
|
||||
}
|
||||
|
||||
export default LayoutSlug
|
||||
@@ -1,24 +0,0 @@
|
||||
import LayoutBase from './LayoutBase'
|
||||
import StickyBar from './components/StickyBar'
|
||||
import TagList from './components/TagList'
|
||||
import BlogPostListScroll from './components/BlogPostListScroll'
|
||||
import BlogPostListPage from './components/BlogPostListPage'
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
export const LayoutTag = (props) => {
|
||||
const { tagOptions, tag } = props
|
||||
|
||||
return <LayoutBase currentTag={tag} {...props}>
|
||||
<StickyBar>
|
||||
<TagList tagOptions={tagOptions} currentTag={tag} />
|
||||
</StickyBar>
|
||||
<div className='md:mt-8'>
|
||||
{BLOG.POST_LIST_STYLE !== 'page'
|
||||
? <BlogPostListScroll {...props} showSummary={true} />
|
||||
: <BlogPostListPage {...props} />
|
||||
}
|
||||
</div>
|
||||
</LayoutBase>
|
||||
}
|
||||
|
||||
export default LayoutTag
|
||||
@@ -1,20 +0,0 @@
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import LayoutBase from './LayoutBase'
|
||||
import TagItem from './components/TagItem'
|
||||
|
||||
export const LayoutTagIndex = (props) => {
|
||||
const { tagOptions } = props
|
||||
const { locale } = useGlobal()
|
||||
return <LayoutBase {...props}>
|
||||
<div className='bg-white dark:bg-hexo-black-gray px-10 py-10 shadow h-full'>
|
||||
<div className='dark:text-gray-200 mb-5'><i className='fas fa-tags mr-4'/>{locale.COMMON.TAGS}:</div>
|
||||
<div id='tags-list' className='duration-200 flex flex-wrap'>
|
||||
{ tagOptions.map(tag => {
|
||||
return <div key={tag.name} className='p-2'><TagItem key={tag.name} tag={tag} /></div>
|
||||
}) }
|
||||
</div>
|
||||
</div>
|
||||
</LayoutBase>
|
||||
}
|
||||
|
||||
export default LayoutTagIndex
|
||||
29
themes/next/components/BlogListBar.js
Normal file
29
themes/next/components/BlogListBar.js
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
import CategoryList from './CategoryList'
|
||||
import StickyBar from './StickyBar'
|
||||
import TagList from './TagList'
|
||||
|
||||
/**
|
||||
* 博客列表上方嵌入
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
export default function BlogListBar(props) {
|
||||
const { tagOptions, tag } = props
|
||||
const { category, categoryOptions } = props
|
||||
if (tag) {
|
||||
return (
|
||||
<StickyBar>
|
||||
<TagList tagOptions={tagOptions} currentTag={tag} />
|
||||
</StickyBar>
|
||||
)
|
||||
} else if (category) {
|
||||
return (
|
||||
<StickyBar>
|
||||
<CategoryList currentCategory={category} categoryOptions={categoryOptions} />
|
||||
</StickyBar>
|
||||
)
|
||||
} else {
|
||||
return <></>
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import Logo from './Logo'
|
||||
import Card from './Card'
|
||||
import CONFIG_NEXT from '../config_next'
|
||||
import BLOG from '@/blog.config'
|
||||
import Live2D from '@/components/Live2D'
|
||||
|
||||
/**
|
||||
* 侧边平铺
|
||||
@@ -66,9 +67,10 @@ const SideAreaLeft = props => {
|
||||
</Tabs>
|
||||
</Card>
|
||||
|
||||
{slot && <div className='flex justify-center'>
|
||||
<div className='flex justify-center'>
|
||||
{slot}
|
||||
</div>}
|
||||
<Live2D />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</aside>
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useRouter } from 'next/router'
|
||||
import BLOG from '@/blog.config'
|
||||
import dynamic from 'next/dynamic'
|
||||
import Announcement from './Announcement'
|
||||
import LatestPostsGroup from './LatestPostsGroup'
|
||||
const NextRecentComments = dynamic(() => import('./NextRecentComments'))
|
||||
|
||||
/**
|
||||
@@ -22,7 +23,7 @@ const NextRecentComments = dynamic(() => import('./NextRecentComments'))
|
||||
* @constructor
|
||||
*/
|
||||
const SideAreaRight = (props) => {
|
||||
const { tagOptions, currentTag, slot, categoryOptions, currentCategory, notice } = props
|
||||
const { tagOptions, currentTag, slot, categoryOptions, currentCategory, notice, latestPosts } = props
|
||||
const { locale } = useGlobal()
|
||||
const router = useRouter()
|
||||
const announcementVisible = notice && Object.keys(notice).length > 0
|
||||
@@ -48,6 +49,7 @@ const SideAreaRight = (props) => {
|
||||
<Announcement post={notice} />
|
||||
</Card>}
|
||||
|
||||
{CONFIG_NEXT.RIGHT_LATEST_POSTS && <Card><LatestPostsGroup latestPosts={latestPosts} /></Card>}
|
||||
{slot}
|
||||
|
||||
{/* 分类 */}
|
||||
|
||||
@@ -10,13 +10,18 @@ import CONFIG_NEXT from '../config_next'
|
||||
* @constructor
|
||||
*/
|
||||
const TocDrawerButton = (props) => {
|
||||
const { locale } = useGlobal()
|
||||
if (!CONFIG_NEXT.WIDGET_TOC) {
|
||||
return <></>
|
||||
}
|
||||
const { locale } = useGlobal()
|
||||
return (<div onClick={props.onClick} className='py-2 px-3 cursor-pointer dark:text-gray-200 text-center transform hover:scale-150 duration-200 flex justify-center items-center' title={locale.POST.TOP} >
|
||||
<i className='fas fa-list-ol'/>
|
||||
</div>)
|
||||
if (props?.post?.toc?.length > 1) {
|
||||
return (
|
||||
<div onClick={props.onClick} className='py-2 px-3 cursor-pointer dark:text-gray-200 text-center transform hover:scale-150 duration-200 flex justify-center items-center' title={locale.POST.TOP} >
|
||||
<i className='fas fa-list-ol' />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <></>
|
||||
}
|
||||
|
||||
export default TocDrawerButton
|
||||
|
||||
@@ -91,37 +91,38 @@ const TopNav = (props) => {
|
||||
)}
|
||||
</>
|
||||
|
||||
return (<div id='top-nav' className='block lg:hidden'>
|
||||
<SearchDrawer cRef={searchDrawer} slot={searchDrawerSlot} />
|
||||
return (
|
||||
<div id='top-nav' className='block lg:hidden'>
|
||||
<SearchDrawer cRef={searchDrawer} slot={searchDrawerSlot} />
|
||||
|
||||
{/* 导航栏 */}
|
||||
<div id='sticky-nav' className={`${CONFIG_NEXT.NAV_TYPE !== 'normal' ? 'fixed' : 'relative'} lg:relative w-full top-0 z-20 transform duration-500`}>
|
||||
<div className='w-full flex justify-between items-center p-4 bg-black dark:bg-gray-800 text-white'>
|
||||
{/* 左侧LOGO 标题 */}
|
||||
<div className='flex flex-none flex-grow-0'>
|
||||
<div onClick={toggleMenuOpen} className='w-8 cursor-pointer'>
|
||||
{isOpen ? <i className='fas fa-times' /> : <i className='fas fa-bars' />}
|
||||
{/* 导航栏 */}
|
||||
<div id='sticky-nav' className={`${CONFIG_NEXT.NAV_TYPE !== 'normal' ? 'fixed' : 'relative'} lg:relative w-full top-0 z-20 transform duration-500`}>
|
||||
<div className='w-full flex justify-between items-center p-4 bg-black dark:bg-gray-800 text-white'>
|
||||
{/* 左侧LOGO 标题 */}
|
||||
<div className='flex flex-none flex-grow-0'>
|
||||
<div onClick={toggleMenuOpen} className='w-8 cursor-pointer'>
|
||||
{isOpen ? <i className='fas fa-times' /> : <i className='fas fa-bars' />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='flex'>
|
||||
<Logo {...props} />
|
||||
</div>
|
||||
|
||||
{/* 右侧功能 */}
|
||||
<div className='mr-1 flex justify-end items-center text-sm space-x-4 font-serif dark:text-gray-200'>
|
||||
<div className="cursor-pointer block lg:hidden" onClick={() => { searchDrawer?.current?.show() }}>
|
||||
<i className="mr-2 fas fa-search" />{locale.NAV.SEARCH}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='flex'>
|
||||
<Logo {...props} />
|
||||
</div>
|
||||
|
||||
{/* 右侧功能 */}
|
||||
<div className='mr-1 flex justify-end items-center text-sm space-x-4 font-serif dark:text-gray-200'>
|
||||
<div className="cursor-pointer block lg:hidden" onClick={() => { searchDrawer?.current?.show() }}>
|
||||
<i className="mr-2 fas fa-search" />{locale.NAV.SEARCH}
|
||||
</div>
|
||||
</div>
|
||||
<Collapse collapseRef={collapseRef} type='vertical' isOpen={isOpen}>
|
||||
<MenuList onHeightChange={(param) => collapseRef.current?.updateCollapseHeight(param)} {...props} from='top' />
|
||||
</Collapse>
|
||||
</div>
|
||||
|
||||
<Collapse collapseRef={collapseRef} type='vertical' isOpen={isOpen}>
|
||||
<MenuList onHeightChange={(param) => collapseRef.current?.updateCollapseHeight(param)} {...props} from='top' />
|
||||
</Collapse>
|
||||
</div>
|
||||
|
||||
</div>)
|
||||
</div>)
|
||||
}
|
||||
|
||||
export default TopNav
|
||||
|
||||
@@ -1,14 +1,319 @@
|
||||
import CONFIG_NEXT from './config_next'
|
||||
import LayoutIndex from './LayoutIndex'
|
||||
import LayoutSearch from './LayoutSearch'
|
||||
import LayoutArchive from './LayoutArchive'
|
||||
import LayoutSlug from './LayoutSlug'
|
||||
import Layout404 from './Layout404'
|
||||
import LayoutCategory from './LayoutCategory'
|
||||
import LayoutCategoryIndex from './LayoutCategoryIndex'
|
||||
import LayoutPage from './LayoutPage'
|
||||
import LayoutTag from './LayoutTag'
|
||||
import LayoutTagIndex from './LayoutTagIndex'
|
||||
|
||||
import CommonHead from '@/components/CommonHead'
|
||||
import FloatDarkModeButton from './components/FloatDarkModeButton'
|
||||
import Footer from './components/Footer'
|
||||
import JumpToBottomButton from './components/JumpToBottomButton'
|
||||
import JumpToTopButton from './components/JumpToTopButton'
|
||||
import LoadingCover from './components/LoadingCover'
|
||||
import SideAreaLeft from './components/SideAreaLeft'
|
||||
import SideAreaRight from './components/SideAreaRight'
|
||||
import TopNav from './components/TopNav'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import BLOG from '@/blog.config'
|
||||
import Header from './components/Header'
|
||||
import BlogPostListScroll from './components/BlogPostListScroll'
|
||||
import BlogPostListPage from './components/BlogPostListPage'
|
||||
import StickyBar from './components/StickyBar'
|
||||
import { isBrowser } from '@/lib/utils'
|
||||
import Mark from 'mark.js'
|
||||
import TocDrawerButton from './components/TocDrawerButton'
|
||||
import TocDrawer from './components/TocDrawer'
|
||||
import { ArticleLock } from './components/ArticleLock'
|
||||
import BlogPostArchive from './components/BlogPostArchive'
|
||||
import TagItem from './components/TagItem'
|
||||
import { useRouter } from 'next/router'
|
||||
import ArticleDetail from './components/ArticleDetail'
|
||||
import Link from 'next/link'
|
||||
import BlogListBar from './components/BlogListBar'
|
||||
|
||||
/**
|
||||
* 基础布局 采用左中右三栏布局,移动端使用顶部导航栏
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
const LayoutBase = (props) => {
|
||||
const { children, headerSlot, meta, floatSlot, rightAreaSlot, siteInfo } = props
|
||||
const { onLoading } = useGlobal()
|
||||
const targetRef = useRef(null)
|
||||
const floatButtonGroup = useRef(null)
|
||||
const [showRightFloat, switchShow] = useState(false)
|
||||
const [percent, changePercent] = useState(0) // 页面阅读百分比
|
||||
|
||||
const scrollListener = () => {
|
||||
const targetRef = document.getElementById('wrapper')
|
||||
const clientHeight = targetRef?.clientHeight
|
||||
const scrollY = window.pageYOffset
|
||||
const fullHeight = clientHeight - window.outerHeight
|
||||
let per = parseFloat(((scrollY / fullHeight * 100)).toFixed(0))
|
||||
if (per > 100) per = 100
|
||||
const shouldShow = scrollY > 100 && per > 0
|
||||
|
||||
if (shouldShow !== showRightFloat) {
|
||||
switchShow(shouldShow)
|
||||
}
|
||||
changePercent(per)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
// facebook messenger 插件需要调整右下角悬浮按钮的高度
|
||||
const fb = document.getElementsByClassName('fb-customerchat')
|
||||
if (fb.length === 0) {
|
||||
floatButtonGroup?.current?.classList.replace('bottom-24', 'bottom-12')
|
||||
} else {
|
||||
floatButtonGroup?.current?.classList.replace('bottom-12', 'bottom-24')
|
||||
}
|
||||
|
||||
document.addEventListener('scroll', scrollListener)
|
||||
return () => document.removeEventListener('scroll', scrollListener)
|
||||
}, [showRightFloat])
|
||||
|
||||
return (
|
||||
<div id='theme-next'>
|
||||
{/* SEO相关 */}
|
||||
<CommonHead meta={meta} />
|
||||
{/* 移动端顶部导航栏 */}
|
||||
<TopNav {...props} />
|
||||
|
||||
<>{headerSlot}</>
|
||||
|
||||
{/* 顶部黑线装饰 */}
|
||||
<div className='h-0.5 w-full bg-gray-700 dark:bg-gray-600 hidden lg:block' />
|
||||
|
||||
{/* 主区 */}
|
||||
<main id='wrapper' className={(BLOG.LAYOUT_SIDEBAR_REVERSE ? 'flex-row-reverse' : '') + ' next relative flex justify-center flex-1 pb-12'}>
|
||||
{/* 左侧栏样式 */}
|
||||
<SideAreaLeft targetRef={targetRef} {...props} />
|
||||
|
||||
{/* 中央内容 */}
|
||||
<section id='container-inner' className={`${CONFIG_NEXT.NAV_TYPE !== 'normal' ? 'mt-24' : ''} lg:max-w-3xl xl:max-w-4xl flex-grow md:mt-0 min-h-screen w-full relative z-10`} ref={targetRef}>
|
||||
{onLoading ? <LoadingCover /> : <> {children}</>}
|
||||
</section>
|
||||
|
||||
{/* 右侧栏样式 */}
|
||||
{CONFIG_NEXT.RIGHT_BAR && <SideAreaRight targetRef={targetRef} slot={rightAreaSlot} {...props} />}
|
||||
</main>
|
||||
|
||||
{/* 右下角悬浮 */}
|
||||
<div ref={floatButtonGroup} className='right-8 bottom-12 lg:right-2 fixed justify-end z-20 font-sans'>
|
||||
<div className={(showRightFloat ? 'animate__animated ' : 'hidden') + ' animate__fadeInUp rounded-md glassmorphism justify-center duration-500 animate__faster flex space-x-2 items-center cursor-pointer '}>
|
||||
<JumpToTopButton percent={percent} />
|
||||
<JumpToBottomButton />
|
||||
<FloatDarkModeButton />
|
||||
{floatSlot}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 页脚 */}
|
||||
<Footer title={siteInfo?.title} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页
|
||||
* 首页就是一个博客列表
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
const LayoutIndex = (props) => {
|
||||
return <LayoutPostList headerSlot={CONFIG_NEXT.HOME_BANNER && <Header {...props} />} {...props} />
|
||||
}
|
||||
|
||||
/**
|
||||
* 博客列表
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
const LayoutPostList = (props) => {
|
||||
return <LayoutBase {...props} >
|
||||
|
||||
<BlogListBar {...props} />
|
||||
|
||||
{BLOG.POST_LIST_STYLE !== 'page'
|
||||
? <BlogPostListScroll {...props} showSummary={true} />
|
||||
: <BlogPostListPage {...props} />
|
||||
}
|
||||
</LayoutBase>
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
const LayoutSearch = (props) => {
|
||||
const { locale } = useGlobal()
|
||||
const { posts, keyword } = props
|
||||
setTimeout(() => {
|
||||
const container = isBrowser() && document.getElementById('posts-wrapper')
|
||||
if (container && container.innerHTML) {
|
||||
const re = new RegExp(keyword, 'gim')
|
||||
const instance = new Mark(container)
|
||||
instance.markRegExp(re, {
|
||||
element: 'span',
|
||||
className: 'text-red-500 border-b border-dashed'
|
||||
})
|
||||
}
|
||||
}, 200)
|
||||
return (
|
||||
<LayoutBase {...props} >
|
||||
<StickyBar>
|
||||
<div className="p-4 dark:text-gray-200">
|
||||
<i className="mr-1 fas fa-search" />{' '}
|
||||
{posts?.length} {locale.COMMON.RESULT_OF_SEARCH}
|
||||
</div>
|
||||
</StickyBar>
|
||||
<div className="md:mt-5">
|
||||
{BLOG.POST_LIST_STYLE !== 'page'
|
||||
? <BlogPostListScroll {...props} showSummary={true} />
|
||||
: <BlogPostListPage {...props} />
|
||||
}
|
||||
</div>
|
||||
</LayoutBase>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 <LayoutBase {...props}>
|
||||
<div className='md:-mt-20 text-black w-full h-screen text-center justify-center content-center items-center flex flex-col'>
|
||||
<div className='dark:text-gray-200'>
|
||||
<h2 className='inline-block border-r-2 border-gray-600 mr-2 px-3 py-2 align-top'><i className='mr-2 fas fa-spinner animate-spin' />404</h2>
|
||||
<div className='inline-block text-left h-32 leading-10 items-center'>
|
||||
<h2 className='m-0 p-0'>页面无法加载,即将返回首页</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</LayoutBase>
|
||||
}
|
||||
|
||||
/**
|
||||
* 归档
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
const LayoutArchive = (props) => {
|
||||
const { archivePosts } = props
|
||||
|
||||
return (
|
||||
<LayoutBase {...props}>
|
||||
<div className="mb-10 pb-20 bg-white md:p-12 p-3 dark:bg-hexo-black-gray shadow-md min-h-full">
|
||||
{Object.keys(archivePosts).map(archiveTitle => (
|
||||
<BlogPostArchive
|
||||
key={archiveTitle}
|
||||
posts={archivePosts[archiveTitle]}
|
||||
archiveTitle={archiveTitle}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</LayoutBase>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章详情
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
const LayoutSlug = (props) => {
|
||||
const { post, lock, validPassword } = props
|
||||
const drawerRight = useRef(null)
|
||||
const targetRef = isBrowser() ? document.getElementById('article-wrapper') : null
|
||||
const floatSlot = <div className='block lg:hidden'>
|
||||
<TocDrawerButton onClick={() => {
|
||||
drawerRight?.current?.handleSwitchVisible()
|
||||
}} />
|
||||
</div>
|
||||
|
||||
return (
|
||||
<LayoutBase {...props} floatSlot={floatSlot}>
|
||||
|
||||
{post && !lock && <ArticleDetail {...props} />}
|
||||
|
||||
{post && lock && <ArticleLock validPassword={validPassword} />}
|
||||
|
||||
{/* 悬浮目录按钮 */}
|
||||
{post && <div className='block lg:hidden'>
|
||||
<TocDrawer post={post} cRef={drawerRight} targetRef={targetRef} />
|
||||
</div>}
|
||||
|
||||
</LayoutBase>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类列表
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
const LayoutCategoryIndex = (props) => {
|
||||
const { allPosts, categoryOptions } = props
|
||||
const { locale } = useGlobal()
|
||||
return (
|
||||
<LayoutBase totalPosts={allPosts} {...props}>
|
||||
<div className='bg-white dark:bg-hexo-black-gray px-10 py-10 shadow h-full'>
|
||||
<div className='dark:text-gray-200 mb-5'>
|
||||
<i className='mr-4 fas faTh' />{locale.COMMON.CATEGORY}:
|
||||
</div>
|
||||
<div id='category-list' className='duration-200 flex flex-wrap'>
|
||||
{categoryOptions.map(category => {
|
||||
return (
|
||||
<Link
|
||||
key={category.name}
|
||||
href={`/category/${category.name}`}
|
||||
passHref
|
||||
legacyBehavior>
|
||||
<div
|
||||
className={'hover:text-black dark:hover:text-white dark:text-gray-300 dark:hover:bg-gray-600 px-5 cursor-pointer py-2 hover:bg-gray-100'}>
|
||||
<i className='mr-4 fas fa-folder' />{category.name}({category.count})
|
||||
</div>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</LayoutBase>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签列表
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
const LayoutTagIndex = (props) => {
|
||||
const { tagOptions } = props
|
||||
const { locale } = useGlobal()
|
||||
return <LayoutBase {...props}>
|
||||
<div className='bg-white dark:bg-hexo-black-gray px-10 py-10 shadow h-full'>
|
||||
<div className='dark:text-gray-200 mb-5'><i className='fas fa-tags mr-4' />{locale.COMMON.TAGS}:</div>
|
||||
<div id='tags-list' className='duration-200 flex flex-wrap'>
|
||||
{tagOptions.map(tag => {
|
||||
return <div key={tag.name} className='p-2'><TagItem key={tag.name} tag={tag} /></div>
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</LayoutBase>
|
||||
}
|
||||
|
||||
export {
|
||||
CONFIG_NEXT as THEME_CONFIG,
|
||||
@@ -17,9 +322,7 @@ export {
|
||||
LayoutArchive,
|
||||
LayoutSlug,
|
||||
Layout404,
|
||||
LayoutCategory,
|
||||
LayoutCategoryIndex,
|
||||
LayoutPage,
|
||||
LayoutTag,
|
||||
LayoutPostList,
|
||||
LayoutTagIndex
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user