From 9db5ba7011c20beab0d852563e8f4181a192c727 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Mon, 20 Mar 2023 08:15:06 +0800 Subject: [PATCH] hexo-custom-menu-apart --- components/Sakura.js | 2 +- pages/[...slug].js | 2 +- themes/hexo/components/DropMenu.js | 67 ++++++++++++++++++++ themes/hexo/components/MenuButtonGroupTop.js | 36 ++++------- themes/hexo/components/MenuList.js | 29 +++------ 5 files changed, 90 insertions(+), 46 deletions(-) create mode 100644 themes/hexo/components/DropMenu.js diff --git a/components/Sakura.js b/components/Sakura.js index e814362f..7898b3cc 100644 --- a/components/Sakura.js +++ b/components/Sakura.js @@ -11,7 +11,7 @@ export const Sakura = () => { useEffect(() => { createSakura({}) - return () => destroyRibbon() + return () => destroySakura() }, []) return <> } diff --git a/pages/[...slug].js b/pages/[...slug].js index e14b98a2..c88570a7 100644 --- a/pages/[...slug].js +++ b/pages/[...slug].js @@ -49,7 +49,7 @@ const Slug = props => { }) } } - }, 8 * 1000) // 404时长 + }, 8 * 1000) // 404时长 8秒 const meta = { title: `${props?.siteInfo?.title || BLOG.TITLE} | loading`, image: siteInfo?.pageCover || BLOG.HOME_BANNER_IMAGE } return } diff --git a/themes/hexo/components/DropMenu.js b/themes/hexo/components/DropMenu.js new file mode 100644 index 00000000..bb508779 --- /dev/null +++ b/themes/hexo/components/DropMenu.js @@ -0,0 +1,67 @@ +import Link from 'next/link' +import { useState } from 'react' + +export const DropMenu = ({ link }) => { + const [show, changeShow] = useState(false) + const hasSubMenu = link?.subMenus?.length > 0 + + return
changeShow(true)} onMouseOut={() => changeShow(false)} > + + {!hasSubMenu && + + {link?.name} + {hasSubMenu && } + } + + {hasSubMenu && <> +
+ {link?.name} + +
+ } + + {/* 子菜单 */} + {hasSubMenu &&
    + {link.subMenus.map(sLink => { + return
  • + + {sLink.title} + +
  • + })} +
} + +
+} + +// + +//
+// +//
{link.name}
+//
+// + +// return ( +// + +//
+// +//
{link.name}
+//
+// {link.slot} + +// +// ) diff --git a/themes/hexo/components/MenuButtonGroupTop.js b/themes/hexo/components/MenuButtonGroupTop.js index 866898e8..e38755b0 100644 --- a/themes/hexo/components/MenuButtonGroupTop.js +++ b/themes/hexo/components/MenuButtonGroupTop.js @@ -1,10 +1,11 @@ import React from 'react' -import Link from 'next/link' import { useGlobal } from '@/lib/global' import CONFIG_HEXO from '../config_hexo' +import { DropMenu } from './DropMenu' +import BLOG from '@/blog.config' const MenuButtonGroupTop = (props) => { - const { customNav } = props + const { customNav, customMenu } = props const { locale } = useGlobal() let links = [ @@ -19,30 +20,15 @@ const MenuButtonGroupTop = (props) => { links = links.concat(customNav) } + // 如果 开启自定义菜单,则覆盖Page生成的菜单 + if (BLOG.CUSTOM_MENU) { + links = customMenu + } + return ( - + ) } export default MenuButtonGroupTop diff --git a/themes/hexo/components/MenuList.js b/themes/hexo/components/MenuList.js index e5579a6a..b3276bfb 100644 --- a/themes/hexo/components/MenuList.js +++ b/themes/hexo/components/MenuList.js @@ -1,11 +1,12 @@ import React from 'react' -import Link from 'next/link' import { useRouter } from 'next/router' import { useGlobal } from '@/lib/global' import CONFIG_HEXO from '../config_hexo' +import BLOG from '@/blog.config' +import { DropMenu } from './DropMenu' const MenuList = (props) => { - const { postCount, customNav } = props + const { postCount, customNav, customMenu } = props const { locale } = useGlobal() const router = useRouter() const archiveSlot =
{postCount}
@@ -21,32 +22,22 @@ const MenuList = (props) => { links = links.concat(customNav) } + // 如果 开启自定义菜单,则覆盖Page生成的菜单 + if (BLOG.CUSTOM_MENU) { + links = customMenu + } + return ( - ); + ) } export default MenuList