From fea352849c6972da4b3b8935eb2e86f6cefc76ed Mon Sep 17 00:00:00 2001
From: Ben Schlegel <ben5.schlegel@gmail.com>
Date: Sat, 16 Sep 2023 17:45:21 +0000
Subject: [PATCH] fix: create deep copy of file passed into tree
---
quartz/components/Explorer.tsx | 23 ++++++++++++++++++++++-
1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/quartz/components/Explorer.tsx b/quartz/components/Explorer.tsx
index ce69491..23c5db2 100644
--- a/quartz/components/Explorer.tsx
+++ b/quartz/components/Explorer.tsx
@@ -11,6 +11,17 @@
folderClickBehavior: "collapse",
folderDefaultState: "collapsed",
useSavedState: true,
+ // Sort order: folders first, then files. Sort folders and files alphabetically
+ sortFn: (a, b) => {
+ if ((!a.file && !b.file) || (a.file && b.file)) {
+ return a.name.localeCompare(b.name)
+ }
+ if (a.file && !b.file) {
+ return 1
+ } else {
+ return -1
+ }
+ },
})
export default ((userOpts?: Partial<Options>) => {
function Explorer({ allFiles, displayClass, fileData }: QuartzComponentProps) {
@@ -22,7 +33,17 @@
allFiles.forEach((file) => fileTree.add(file, 1))
// Sort tree (folders first, then files (alphabetic))
- fileTree.sort()
+ fileTree.sort(opts.sortFn!)
+
+ // If provided, apply filter function to fileTree
+ if (opts.filterFn) {
+ fileTree.filter(opts.filterFn)
+ }
+
+ // If provided, apply map function to fileTree
+ if (opts.mapFn) {
+ fileTree.map(opts.mapFn)
+ }
// Get all folders of tree. Initialize with collapsed state
const folders = fileTree.getFolderPaths(opts.folderDefaultState === "collapsed")
--
Gitblit v1.10.0