From 270a5dc14ac3654c3aac94dfca222bab0d091474 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Wed, 12 Mar 2025 18:24:28 +0000
Subject: [PATCH] fix(explorer): show file name instead of slug if no file data (closes #1822)

---
 quartz/util/fileTrie.ts |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/quartz/util/fileTrie.ts b/quartz/util/fileTrie.ts
index 8f4bfcb..b39833c 100644
--- a/quartz/util/fileTrie.ts
+++ b/quartz/util/fileTrie.ts
@@ -4,6 +4,7 @@
 interface FileTrieData {
   slug: string
   title: string
+  filePath: string
 }
 
 export class FileTrieNode<T extends FileTrieData = ContentDetails> {
@@ -11,6 +12,10 @@
   children: Array<FileTrieNode<T>>
 
   private slugSegments: string[]
+  // prefer showing the file path segment over the slug segment
+  // so that folders that dont have index files can be shown as is
+  // without dashes in the slug
+  private fileSegmentHint?: string
   private displayNameOverride?: string
   data: T | null
 
@@ -23,7 +28,10 @@
   }
 
   get displayName(): string {
-    return this.displayNameOverride ?? this.data?.title ?? this.slugSegment ?? ""
+    const nonIndexTitle = this.data?.title === "index" ? undefined : this.data?.title
+    return (
+      this.displayNameOverride ?? nonIndexTitle ?? this.fileSegmentHint ?? this.slugSegment ?? ""
+    )
   }
 
   set displayName(name: string) {
@@ -69,6 +77,9 @@
       // recursive case, we are not at the end of the path
       const child =
         this.children.find((c) => c.slugSegment === segment) ?? this.makeChild(path, undefined)
+
+      const fileParts = file.filePath.split("/")
+      child.fileSegmentHint = fileParts.at(-path.length)
       child.insert(path.slice(1), file)
     }
   }

--
Gitblit v1.10.0