From d3c2b9d5b645b1664a9537d8ad0a1b7211269da4 Mon Sep 17 00:00:00 2001 From: PrOF-kk Date: Sun, 11 Jan 2026 18:01:45 +0100 Subject: [PATCH] Initial support for folder notes --- src/helpers/filetreeUtils.js | 22 +++++++++++++++++++++- src/site/_includes/components/filetree.njk | 16 ++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/helpers/filetreeUtils.js b/src/helpers/filetreeUtils.js index 853f38c69e..a9aad03cb2 100644 --- a/src/helpers/filetreeUtils.js +++ b/src/helpers/filetreeUtils.js @@ -87,7 +87,7 @@ function getPermalinkMeta(note, key) { } if (note.data.tags && note.data.tags.indexOf("gardenEntry") != -1) { permalink = "/"; - } + } if (note.data.title) { name = note.data.title; } @@ -133,12 +133,32 @@ function assignNested(obj, keyPath, value) { obj[keyPath[lastKeyIndex]] = value; } +/** + * A folder note is a note with the same filename as the parent folder. + * Hide the folder note and link to it from the folder to treat it as a special case. + * + * @returns {void} + */ +function detectFoldersWithFolderNotes(parentName, parent) { + // Check if any of the children are notes with the same name + for (const [childName, child] of Object.entries(parent)) { + if (child.isNote && childName === (parentName + ".md")) { + // Found a folder note, hide the standalone link + child.hide = true; + parent.folderNote = child; + } else if (child.isFolder) { + detectFoldersWithFolderNotes(childName, child); + } + } +} + function getFileTree(data) { const tree = {}; (data.collections.note || []).forEach((note) => { const [meta, folders] = getPermalinkMeta(note); assignNested(tree, folders, { isNote: true, ...meta }); }); + detectFoldersWithFolderNotes(null, tree); const fileTree = sortTree(tree); return fileTree; } diff --git a/src/site/_includes/components/filetree.njk b/src/site/_includes/components/filetree.njk index 83cebbc4f9..952b626860 100644 --- a/src/site/_includes/components/filetree.njk +++ b/src/site/_includes/components/filetree.njk @@ -3,14 +3,18 @@