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 RandomPostButton from './RandomPostButton' import SearchButton from './SearchButton' import { siteConfig } from '@/lib/config' const Nav = props => { const { navBarTitle, fullWidth, siteInfo } = props const useSticky = !JSON.parse(siteConfig('NOBELIUM_AUTO_COLLAPSE_NAV_BAR', true)) const navRef = useRef(null) const sentinalRef = useRef([]) const handler = ([entry]) => { if (navRef && navRef.current && useSticky) { if (!entry.isIntersecting && entry !== undefined) { navRef.current?.classList.add('sticky-nav-full') } else { navRef.current?.classList.remove('sticky-nav-full') } } else { navRef.current?.classList.add('remove-sticky') } } useEffect(() => { const obvserver = new window.IntersectionObserver(handler) obvserver.observe(sentinalRef.current) return () => { if (sentinalRef.current) obvserver.unobserve(sentinalRef.current) } }, [sentinalRef]) return <>
} const NavBar = props => { const { customMenu, customNav } = props const [isOpen, changeOpen] = useState(false) const toggleOpen = () => { changeOpen(!isOpen) } const collapseRef = useRef(null) const { locale } = useGlobal() let links = [ { id: 2, name: locale.NAV.RSS, to: '/feed', show: siteConfig('ENABLE_RSS') && siteConfig('NOBELIUM_MENU_RSS', null, CONFIG), target: '_blank' }, { icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: siteConfig('NOBELIUM_MENU_SEARCH', null, CONFIG) }, { icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: siteConfig('NOBELIUM_MENU_ARCHIVE', null, CONFIG) }, { icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: siteConfig('NOBELIUM_MENU_CATEGORY', null, CONFIG) }, { icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: siteConfig('NOBELIUM_MENU_TAG', null, CONFIG) } ] if (customNav) { links = links.concat(customNav) } // 如果 开启自定义菜单,则覆盖Page生成的菜单 if (siteConfig('CUSTOM_MENU')) { links = customMenu } if (!links || links.length === 0) { return null } return (
{links?.map((link, index) => collapseRef.current?.updateCollapseHeight(param)}/>)}
{JSON.parse(siteConfig('NOBELIUM_MENU_RANDOM_POST', null, CONFIG)) && } {JSON.parse(siteConfig('NOBELIUM_MENU_SEARCH_BUTTON', null, CONFIG)) && }
) } export default Nav