From 80c7b505daa50e4dcf137798b56787050bf2ea6b Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sat, 21 Sep 2024 23:04:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?gitbook=E5=AF=BC=E8=88=AA=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E6=82=AC=E5=81=9C=E8=87=AA=E5=8A=A8=E5=B1=95=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/gitbook/components/NavPostItem.js | 13 +++++++++++-- themes/gitbook/components/NavPostList.js | 3 ++- themes/gitbook/config.js | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/themes/gitbook/components/NavPostItem.js b/themes/gitbook/components/NavPostItem.js index 4961d7de3e6..0110be776f0 100644 --- a/themes/gitbook/components/NavPostItem.js +++ b/themes/gitbook/components/NavPostItem.js @@ -14,12 +14,20 @@ import BlogPostCard from './BlogPostCard' const NavPostItem = props => { const { group, expanded, toggleItem } = props // 接收传递的展开状态和切换函数 // const [isOpen, setIsOpen] = useState(expanded) // 使用展开状态作为组件内部状态 + const hoverExpand = siteConfig('GITBOOK_FOLDER_HOVER_EXPAND', false, CONFIG) // 当展开状态改变时触发切换函数,并根据传入的展开状态更新内部状态 const toggleOpenSubMenu = () => { toggleItem() // 调用父组件传递的切换函数 // setIsOpen(!expanded) // 更新内部状态为传入的展开状态的相反值 } + const onHoverToggle = () => { + // 允许鼠标悬停时自动展开,而非点击展开 + if (!hoverExpand) { + return + } + toggleOpenSubMenu() + } const groupHasLatest = group?.items?.some(post => post.isLatest) @@ -27,13 +35,14 @@ const NavPostItem = props => { return ( <>
{group?.category}
+ className={`px-2 fas fa-chevron-left transition-all opacity-50 duration-700 ${expanded ? '-rotate-90' : ''}`}>
{groupHasLatest && siteConfig('GITBOOK_LATEST_POST_RED_BADGE', false, CONFIG) && diff --git a/themes/gitbook/components/NavPostList.js b/themes/gitbook/components/NavPostList.js index a67bc7fd7b4..7bc67c442c4 100644 --- a/themes/gitbook/components/NavPostList.js +++ b/themes/gitbook/components/NavPostList.js @@ -105,6 +105,7 @@ function groupArticles(filteredNavPages) { return [] } const groups = [] + const AUTO_SORT = siteConfig('GITBOOK_AUTO_SORT', true, CONFIG) for (let i = 0; i < filteredNavPages.length; i++) { const item = filteredNavPages[i] @@ -112,7 +113,7 @@ function groupArticles(filteredNavPages) { let existingGroup = null // 开启自动分组排序;将同分类的自动归到同一个文件夹,忽略Notion中的排序 - if (siteConfig('GITBOOK_AUTO_SORT', true, CONFIG)) { + if (AUTO_SORT) { existingGroup = groups.find(group => group.category === categoryName) // 搜索同名的最后一个分组 } else { existingGroup = groups[groups.length - 1] // 获取最后一个分组 diff --git a/themes/gitbook/config.js b/themes/gitbook/config.js index 3e376bbb092..4cbb50b4fd2 100644 --- a/themes/gitbook/config.js +++ b/themes/gitbook/config.js @@ -15,6 +15,8 @@ const CONFIG = { // 导航文章自动排他折叠 GITBOOK_EXCLUSIVE_COLLAPSE: true, // 一次只展开一个分类,其它文件夹自动关闭。 + GITBOOK_FOLDER_HOVER_EXPAND: true, // 左侧导航文件夹鼠标悬停时自动展开;若为false,则要点击才能展开 + // Widget GITBOOK_WIDGET_REVOLVER_MAPS: process.env.NEXT_PUBLIC_WIDGET_REVOLVER_MAPS || 'false', // 地图插件 From 1d1b81e8d92f7d37250a610d6583ff616101218c Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sat, 21 Sep 2024 23:08:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Collapse=E7=BB=84=E4=BB=B6=E5=8A=A8?= =?UTF-8?q?=E7=94=BB=E9=80=9F=E5=BA=A6=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Collapse.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/components/Collapse.js b/components/Collapse.js index 69ef59ebca7..dd36f14fe28 100644 --- a/components/Collapse.js +++ b/components/Collapse.js @@ -26,9 +26,9 @@ const Collapse = props => { }) /** - * 折叠 - * @param {*} element - */ + * 折叠 + * @param {*} element + */ const collapseSection = element => { const sectionHeight = element.scrollHeight const sectionWidth = element.scrollWidth @@ -51,9 +51,9 @@ const Collapse = props => { } /** - * 展开 - * @param {*} element - */ + * 展开 + * @param {*} element + */ const expandSection = element => { const sectionHeight = element.scrollHeight const sectionWidth = element.scrollWidth @@ -82,13 +82,24 @@ const Collapse = props => { collapseSection(ref.current) } // 通知父组件高度变化 - props?.onHeightChange && props.onHeightChange({ height: ref.current.scrollHeight, increase: props.isOpen }) + props?.onHeightChange && + props.onHeightChange({ + height: ref.current.scrollHeight, + increase: props.isOpen + }) }, [props.isOpen]) return ( -
- {props.children} -
+
+ {props.children} +
) } Collapse.defaultProps = { isOpen: false }