diff --git a/themes/nobelium/components/Nav.js b/themes/nobelium/components/Nav.js index 38253b43..a30618ed 100644 --- a/themes/nobelium/components/Nav.js +++ b/themes/nobelium/components/Nav.js @@ -1,24 +1,31 @@ -import { useEffect, useRef, useState } from 'react' -import Link from 'next/link' -import { useGlobal } from '@/lib/global' -import CONFIG from '../config' -import { SvgIcon } from './SvgIcon' -import { MenuItemDrop } from './MenuItemDrop' import Collapse from '@/components/Collapse' -import { MenuItemCollapse } from './MenuItemCollapse' import LazyImage from '@/components/LazyImage' +import { siteConfig } from '@/lib/config' +import { useGlobal } from '@/lib/global' +import Link from 'next/link' +import { useEffect, useRef, useState } from 'react' +import CONFIG from '../config' +import { MenuItemCollapse } from './MenuItemCollapse' +import { MenuItemDrop } from './MenuItemDrop' import RandomPostButton from './RandomPostButton' import SearchButton from './SearchButton' -import { siteConfig } from '@/lib/config' - +import { SvgIcon } from './SvgIcon' +/** + * 顶部导航 + */ const Nav = props => { const { navBarTitle, fullWidth, siteInfo } = props - const useSticky = !JSON.parse(siteConfig('NOBELIUM_AUTO_COLLAPSE_NAV_BAR', true)) + const autoCollapseNavBar = siteConfig( + 'NOBELIUM_AUTO_COLLAPSE_NAV_BAR', + true, + CONFIG + ) + const navRef = useRef(null) const sentinalRef = useRef([]) const handler = ([entry]) => { - if (navRef && navRef.current && useSticky) { - if (!entry.isIntersecting && entry !== undefined) { + if (navRef && navRef.current && autoCollapseNavBar) { + if (!entry?.isIntersecting) { navRef.current?.classList.add('sticky-nav-full') } else { navRef.current?.classList.remove('sticky-nav-full') @@ -34,42 +41,46 @@ const Nav = props => { if (sentinalRef.current) obvserver.unobserve(sentinalRef.current) } }, [sentinalRef]) - return <> -
-