Skip to content

Commit 16d33fb

Browse files
authored
feat: display name for folders, expand explorer a little bit (#489)
* feat: display name for folders, expand explorer a little bit * update docs
1 parent b029eea commit 16d33fb

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

docs/advanced/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: "Advanced"
3+
---

docs/features/explorer.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ All functions you can pass work with the `FileNode` class, which has the followi
5757
```ts title="quartz/components/ExplorerNode.tsx" {2-5}
5858
export class FileNode {
5959
children: FileNode[] // children of current node
60-
name: string // name of node (only useful for folders)
60+
name: string // last part of slug
61+
displayName: string // what actually should be displayed in the explorer
6162
file: QuartzPluginData | null // set if node is a file, see `QuartzPluginData` for more detail
6263
depth: number // depth of current node
6364

@@ -72,7 +73,7 @@ Every function you can pass is optional. By default, only a `sort` function will
7273
Component.Explorer({
7374
sortFn: (a, b) => {
7475
if ((!a.file && !b.file) || (a.file && b.file)) {
75-
return a.name.localeCompare(b.name)
76+
return a.displayName.localeCompare(b.displayName)
7677
}
7778
if (a.file && !b.file) {
7879
return 1
@@ -120,7 +121,7 @@ Using this example, the explorer will alphabetically sort everything, but put al
120121
Component.Explorer({
121122
sortFn: (a, b) => {
122123
if ((!a.file && !b.file) || (a.file && b.file)) {
123-
return a.name.localeCompare(b.name)
124+
return a.displayName.localeCompare(b.displayName)
124125
}
125126
if (a.file && !b.file) {
126127
return -1
@@ -138,7 +139,7 @@ Using this example, the display names of all `FileNodes` (folders + files) will
138139
```ts title="quartz.layout.ts"
139140
Component.Explorer({
140141
mapFn: (node) => {
141-
node.name = node.name.toUpperCase()
142+
node.displayName = node.displayName.toUpperCase()
142143
},
143144
})
144145
```
@@ -172,9 +173,9 @@ Component.Explorer({
172173
if (node.depth > 0) {
173174
// set emoji for file/folder
174175
if (node.file) {
175-
node.name = "📄 " + node.name
176+
node.displayName = "📄 " + node.displayName
176177
} else {
177-
node.name = "📁 " + node.name
178+
node.displayName = "📁 " + node.displayName
178179
}
179180
}
180181
},

quartz/components/Explorer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ const defaultOptions = {
1111
folderClickBehavior: "collapse",
1212
folderDefaultState: "collapsed",
1313
useSavedState: true,
14-
// Sort order: folders first, then files. Sort folders and files alphabetically
1514
sortFn: (a, b) => {
15+
// Sort order: folders first, then files. Sort folders and files alphabetically
1616
if ((!a.file && !b.file) || (a.file && b.file)) {
17-
return a.name.localeCompare(b.name)
17+
return a.displayName.localeCompare(b.displayName)
1818
}
1919
if (a.file && !b.file) {
2020
return 1
2121
} else {
2222
return -1
2323
}
2424
},
25+
filterFn: (node) => node.name !== "tags",
2526
order: ["filter", "map", "sort"],
2627
} satisfies Options
2728

quartz/components/ExplorerNode.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,25 @@ export type FolderState = {
2929
export class FileNode {
3030
children: FileNode[]
3131
name: string
32+
displayName: string
3233
file: QuartzPluginData | null
3334
depth: number
3435

3536
constructor(name: string, file?: QuartzPluginData, depth?: number) {
3637
this.children = []
3738
this.name = name
39+
this.displayName = name
3840
this.file = file ? structuredClone(file) : null
3941
this.depth = depth ?? 0
4042
}
4143

4244
private insert(file: DataWrapper) {
4345
if (file.path.length === 1) {
44-
this.children.push(new FileNode(file.file.frontmatter!.title, file.file, this.depth + 1))
46+
if (file.path[0] !== "index.md") {
47+
this.children.push(new FileNode(file.file.frontmatter!.title, file.file, this.depth + 1))
48+
} else {
49+
this.displayName = file.file.frontmatter!.title
50+
}
4551
} else {
4652
const next = file.path[0]
4753
file.path = file.path.splice(1)
@@ -150,7 +156,7 @@ export function ExplorerNode({ node, opts, fullPath, fileData }: ExplorerNodePro
150156
// Single file node
151157
<li key={node.file.slug}>
152158
<a href={resolveRelative(fileData.slug!, node.file.slug!)} data-for={node.file.slug}>
153-
{node.name}
159+
{node.displayName}
154160
</a>
155161
</li>
156162
) : (
@@ -177,11 +183,11 @@ export function ExplorerNode({ node, opts, fullPath, fileData }: ExplorerNodePro
177183
<div key={node.name} data-folderpath={folderPath}>
178184
{folderBehavior === "link" ? (
179185
<a href={`${folderPath}`} data-for={node.name} class="folder-title">
180-
{node.name}
186+
{node.displayName}
181187
</a>
182188
) : (
183189
<button class="folder-button">
184-
<p class="folder-title">{node.name}</p>
190+
<p class="folder-title">{node.displayName}</p>
185191
</button>
186192
)}
187193
</div>

quartz/styles/base.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ video {
446446

447447
ul.overflow,
448448
ol.overflow {
449-
max-height: 300;
449+
max-height: 400;
450450
overflow-y: auto;
451451

452452
// clearfix

0 commit comments

Comments
 (0)