Skip to content

Commit caf89af

Browse files
committed
change sorting of explore to put Introduction and ELI5 above all else, and files come before folders.
1 parent 792c208 commit caf89af

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

quartz/quartz.layout.ts

+32-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,36 @@ export const sharedPageComponents: SharedLayout = {
1414
}),
1515
}
1616

17+
const explorer = Component.Explorer({
18+
sortFn: (a, b) => {
19+
// Helper function to prioritise "Introduction" and "ELI5"
20+
const priority = (name : string) => {
21+
if (name === "Introduction") return -2; // Highest priority
22+
if (name === "ELI5") return -1; // Second highest priority
23+
return 0; // No priority
24+
};
25+
26+
// Check if both are files or directories
27+
const aIsFile = typeof a.file !== null;
28+
const bIsFile = typeof b.file !== null;
29+
30+
// Prioritize specific filenames first
31+
const aPriority = priority(a.name);
32+
const bPriority = priority(b.name);
33+
34+
// If either has a priority, sort based on that
35+
if (aPriority !== bPriority) return aPriority - bPriority;
36+
37+
// If one is a file and the other is a directory, sort files first
38+
if (aIsFile && !bIsFile) return -1; // a is a file, b is a directory
39+
if (!aIsFile && bIsFile) return 1; // a is a directory, b is a file
40+
41+
// If both are either files or directories, sort alphabetically
42+
return a.name.localeCompare(b.name);
43+
}
44+
});
45+
46+
1747
// components for pages that display a single page (e.g. a single note)
1848
export const defaultContentPageLayout: PageLayout = {
1949
beforeBody: [
@@ -27,7 +57,7 @@ export const defaultContentPageLayout: PageLayout = {
2757
Component.MobileOnly(Component.Spacer()),
2858
Component.Search(),
2959
Component.Darkmode(),
30-
Component.DesktopOnly(Component.Explorer()),
60+
Component.DesktopOnly(explorer),
3161
],
3262
right: [
3363
Component.Graph(),
@@ -44,7 +74,7 @@ export const defaultListPageLayout: PageLayout = {
4474
Component.MobileOnly(Component.Spacer()),
4575
Component.Search(),
4676
Component.Darkmode(),
47-
Component.DesktopOnly(Component.Explorer()),
77+
Component.DesktopOnly(explorer),
4878
],
4979
right: [],
5080
}

0 commit comments

Comments
 (0)