From c005fe440895c3533e6a263d8ad4c63df5a1ad2b Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Wed, 12 Mar 2025 22:31:44 -0700 Subject: [PATCH] fix(explorer): properly respect folderDefaultState (closes #1827) --- quartz/components/scripts/explorer.inline.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/quartz/components/scripts/explorer.inline.ts b/quartz/components/scripts/explorer.inline.ts index d1a74d6..e9c0a09 100644 --- a/quartz/components/scripts/explorer.inline.ts +++ b/quartz/components/scripts/explorer.inline.ts @@ -161,7 +161,7 @@ async function setupExplorer(currentSlug: FullSlug) { // Get folder state from local storage const storageTree = localStorage.getItem("fileTree") const serializedExplorerState = storageTree && opts.useSavedState ? JSON.parse(storageTree) : [] - const oldIndex = new Map( + const oldIndex = new Map( serializedExplorerState.map((entry: FolderState) => [entry.path, entry.collapsed]), ) @@ -186,10 +186,14 @@ async function setupExplorer(currentSlug: FullSlug) { // Get folder paths for state management const folderPaths = trie.getFolderPaths() - currentExplorerState = folderPaths.map((path) => ({ - path, - collapsed: oldIndex.get(path) === true, - })) + currentExplorerState = folderPaths.map((path) => { + const previousState = oldIndex.get(path) + return { + path, + collapsed: + previousState === undefined ? opts.folderDefaultState === "collapsed" : previousState, + } + }) const explorerUl = explorer.querySelector(".explorer-ul") if (!explorerUl) continue