diff --git a/themes/Hexo/LayoutSlug.js b/themes/Hexo/LayoutSlug.js index b03095b9..87c69bee 100644 --- a/themes/Hexo/LayoutSlug.js +++ b/themes/Hexo/LayoutSlug.js @@ -1,10 +1,5 @@ import BLOG from '@/blog.config' -import formatDate from '@/lib/formatDate' -import { useGlobal } from '@/lib/global' import { getPageTableOfContents } from 'notion-utils' -import { faFolderOpen } from '@fortawesome/free-solid-svg-icons' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import Link from 'next/link' import 'prismjs' import 'prismjs/components/prism-bash' import 'prismjs/components/prism-java' @@ -12,12 +7,12 @@ import 'prismjs/components/prism-javascript' import 'prismjs/components/prism-markup' import 'prismjs/components/prism-python' import 'prismjs/components/prism-typescript' -import CONFIG_NEXT from '../NEXT/config_next' -import ArticleDetail from './components/ArticleDetail' -import LayoutBase from './LayoutBase' -import TocDrawerButton from './components/TocDrawerButton' import { useRef } from 'react' +import ArticleDetail from './components/ArticleDetail' +import HeaderArticle from './components/HeaderArticle' import TocDrawer from './components/TocDrawer' +import TocDrawerButton from './components/TocDrawerButton' +import LayoutBase from './LayoutBase' export const LayoutSlug = props => { const { post } = props @@ -28,64 +23,11 @@ export const LayoutSlug = props => { tags: post.tags } - const { locale } = useGlobal() - const date = formatDate( - post?.date?.start_date || post.createdTime, - locale.LOCALE - ) - if (post?.blockMap?.block) { post.content = Object.keys(post.blockMap.block) post.toc = getPageTableOfContents(post, post.blockMap) } - const headerImage = post?.page_cover ? `url("${post.page_cover}")` : `url("/${CONFIG_NEXT.HOME_BANNER_IMAGE}")` - const headerSlot = ( -
-
-
- {/* 文章Title */} -
- {post.title} -
- -
-
- - - - {post.category} - - - | - - {post.type[0] !== 'Page' && ( - <> - - - {date} - - - - )} - -
- | - - 次访问 -
-
-
-
-
-
- ) const drawerRight = useRef(null) const targetRef = typeof window !== 'undefined' ? document.getElementById('container') : null @@ -104,7 +46,7 @@ export const LayoutSlug = props => { return ( } {...props} meta={meta} showCategory={false} diff --git a/themes/Hexo/components/Header.js b/themes/Hexo/components/Header.js index c55aac64..6a527cb8 100644 --- a/themes/Hexo/components/Header.js +++ b/themes/Hexo/components/Header.js @@ -1,3 +1,4 @@ +import BLOG from '@/blog.config' import { useGlobal } from '@/lib/global' import { faAngleDown } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' @@ -15,7 +16,12 @@ let autoScroll = false */ export default function Header () { const [typed, changeType] = useState() + const { theme } = useGlobal() + useEffect(() => { + scrollTrigger() + updateHeaderHeight() + updateTopNav() if (!typed && window && document.getElementById('typed')) { changeType( new Typed('#typed', { @@ -28,8 +34,13 @@ export default function Header () { }) ) } + window.addEventListener('scroll', scrollTrigger) + window.addEventListener('resize', updateHeaderHeight) + return () => { + window.removeEventListener('scroll', scrollTrigger) + window.removeEventListener('resize', updateHeaderHeight) + } }) - const { theme } = useGlobal() const autoScrollEnd = () => { if (autoScroll) { @@ -39,25 +50,29 @@ export default function Header () { } const scrollTrigger = () => { - if ( - (window.scrollY > windowTop) & - (window.scrollY < window.innerHeight) && - !autoScroll + const scrollS = window.scrollY + const nav = document.querySelector('#sticky-nav') + + if (scrollS < 300) { + nav && nav.classList.replace('bg-white', 'bg-none') + nav && nav.classList.replace('text-black', 'text-white') + } else { + nav && nav.classList.replace('bg-none', 'bg-white') + nav && nav.classList.replace('text-white', 'text-black') + } + + if ((scrollS > windowTop) & (scrollS < window.innerHeight) && !autoScroll ) { autoScroll = true window.scrollTo({ top: wrapperTop, behavior: 'smooth' }) setTimeout(autoScrollEnd, 500) } - if ( - (window.scrollY < windowTop) & - (window.scrollY < window.innerHeight) && - !autoScroll - ) { + if ((scrollS < windowTop) && (scrollS < window.innerHeight) && !autoScroll) { autoScroll = true window.scrollTo({ top: 0, behavior: 'smooth' }) setTimeout(autoScrollEnd, 500) } - windowTop = window.scrollY + windowTop = scrollS updateTopNav() } @@ -82,17 +97,6 @@ export default function Header () { }, 500) } - useEffect(() => { - updateHeaderHeight() - updateTopNav() - window.addEventListener('scroll', scrollTrigger) - window.addEventListener('resize', updateHeaderHeight) - return () => { - window.removeEventListener('scroll', scrollTrigger) - window.removeEventListener('resize', updateHeaderHeight) - } - }) - return (