From b2960bad2852293fd7465324f546540c7744af8c Mon Sep 17 00:00:00 2001 From: ZTL-UwU Date: Tue, 5 Nov 2024 17:34:22 +0800 Subject: [PATCH] fix: override configured collase with that defined in _dir Signed-off-by: ZTL-UwU --- components/layout/AsideTreeItem.vue | 10 +++++++++- content/1.getting-started/3.writing/3.folders.md | 3 ++- nuxt.config.ts | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/components/layout/AsideTreeItem.vue b/components/layout/AsideTreeItem.vue index 860a3460..f1f21bc8 100644 --- a/components/layout/AsideTreeItem.vue +++ b/components/layout/AsideTreeItem.vue @@ -88,7 +88,15 @@ const { link, level } = defineProps<{ const { collapse, folderStyle: defaultFolderStyle } = useConfig().value.aside; const collapsed = useCollapsedMap(); -const isOpen = ref(collapsed.value.get(link._path) || (level < 1 && !collapse && !link.collapsed)); +const isOpen = ref(collapsed.value.get(link._path) || defaultOpen()); + +function defaultOpen() { + if (link.collapse !== undefined) + return !link.collapse; + + return level < 1 && !collapse; +} + watch(isOpen, (v) => { collapsed.value.set(link._path, v); }); diff --git a/content/1.getting-started/3.writing/3.folders.md b/content/1.getting-started/3.writing/3.folders.md index 37b26d8b..e130fdb7 100644 --- a/content/1.getting-started/3.writing/3.folders.md +++ b/content/1.getting-started/3.writing/3.folders.md @@ -16,6 +16,7 @@ navBadges: type: lime sidebar: style: group +collapse: false ``` ```[Directory structure] content/ @@ -38,7 +39,7 @@ content/ ::field{name="navBadges" type="[]"} A list of badges appended to the end of the sidebar link. :: - ::field{name="collapsed" type="boolean"} + ::field{name="collapse" type="boolean"} Whether the folder should be collapsed by default. :: ::field{name="sidebar" type="object"} diff --git a/nuxt.config.ts b/nuxt.config.ts index e7b19ee0..a6ff1309 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -50,7 +50,7 @@ export default defineNuxtConfig({ 'badges', 'toc', 'sidebar', - 'collapsed', + 'collapse', ], }, experimental: {