Quartz features an explorer that allows you to navigate all files and folders on your site. It supports nested folders and is highly customizable.
By default, it shows all folders and files on your page. To display the explorer in a different spot, you can edit the layout.
Display names for folders get determined by the title
frontmatter field in folder/index.md
(more detail in Authoring Content). If this file does not exist or does not contain frontmatter, the local folder name will be used instead.
Info
The explorer uses local storage by default to save the state of your explorer. This is done to ensure a smooth experience when navigating to different pages.
To clear/delete the explorer state from local storage, delete the
fileTree
entry (guide on how to delete a key from local storage in chromium based browsers can be found here). You can disable this by passinguseSavedState: false
as an argument.
Customization
Most configuration can be done by passing in options to Component.Explorer()
.
For example, here’s what the default configuration looks like:
When passing in your own options, you can omit any or all of these fields if you’d like to keep the default value for that field.
Want to customize it even more?
- Removing table of contents: remove
Component.Explorer()
fromquartz.layout.ts
- (optional): After removing the explorer component, you can move the Table of Contents component back to the
left
part of the layout
- (optional): After removing the explorer component, you can move the Table of Contents component back to the
- Changing
sort
,filter
andmap
behavior: explained in Advanced customization - Component:
- Wrapper (Outer component, generates file tree, etc):
quartz/components/Explorer.tsx
- Explorer node (recursive, either a folder or a file):
quartz/components/ExplorerNode.tsx
- Wrapper (Outer component, generates file tree, etc):
- Style:
quartz/components/styles/explorer.scss
- Script:
quartz/components/scripts/explorer.inline.ts
Advanced customization
This component allows you to fully customize all of its behavior. You can pass a custom sort
, filter
and map
function.
All functions you can pass work with the FileNode
class, which has the following properties:
Every function you can pass is optional. By default, only a sort
function will be used:
You can pass your own functions for sortFn
, filterFn
and mapFn
. All functions will be executed in the order provided by the order
option (see Customization). These functions behave similarly to their Array.prototype
counterpart, except they modify the entire FileNode
tree in place instead of returning a new one.
For more information on how to use sort
, filter
and map
, you can check Array.prototype.sort(), Array.prototype.filter() and Array.prototype.map().
Type definitions look like this:
Tip
You can check if a
FileNode
is a folder or a file like this:
Basic examples
These examples show the basic usage of sort
, map
and filter
.
Use sort
to put files first
Using this example, the explorer will alphabetically sort everything, but put all files above all folders.
Change display names (map
)
Using this example, the display names of all FileNodes
(folders + files) will be converted to full upper case.
Remove list of elements (filter
)
Using this example, you can remove elements from your explorer by providing an array of folders/files using the omit
set.
You can customize this by changing the entries of the omit
set. Simply add all folder or file names you want to remove.
Show every element in explorer
To override the default filter function that removes the tags
folder from the explorer, you can set the filter function to undefined
.
Advanced examples
Tip
When writing more complicated functions, the
layout
file can start to look very cramped. You can fix this by defining your functions in another file.You can then import them like this:
Add emoji prefix
To add emoji prefixes (📁 for folders, 📄 for files), you could use a map function like this:
Putting it all together
In this example, we’re going to customize the explorer by using functions from examples above to add emoji prefixes, filter out some folders and sort with files above folders.
Notice how we customized the order
array here. This is done because the default order applies the sort
function last. While this normally works well, it would cause unintended behavior here, since we changed the first characters of all display names. In our example, sort
would be applied based off the emoji prefix instead of the first real character.
To fix this, we just changed around the order and apply the sort
function before changing the display names in the map
function.
Use sort
with pre-defined sort order
Here’s another example where a map containing file/folder names (as slugs) is used to define the sort order of the explorer in quartz. All files/folders that aren’t listed inside of nameOrderMap
will appear at the top of that folders hierarchy level.
It’s also worth mentioning, that the smaller the number set in nameOrderMap
, the higher up the entry will be in the explorer. Incrementing every folder/file by 100, makes ordering files in their folders a lot easier. Lastly, this example still allows you to use a mapFn
or frontmatter titles to change display names, as it uses slugs for nameOrderMap
(which is unaffected by display name changes).
For reference, this is how the quartz explorer window would look like with that example:
📖 Poetry Folder
📑 Essay Folder
⚗️ Research Paper File
🦴 Dinosaur Fossils File
🔮 Other Folder
And this is how the file structure would look like:
index.md
poetry-folder
index.md
essay-folder
index.md
research-paper-file.md
dinosaur-fossils-file.md
other-folder
index.md