Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/helpers/filetreeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 10 additions & 6 deletions src/site/_includes/components/filetree.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
<div x-show="isOpen" style="display:none" class="{{'filelist' if step>0}}">
{%if fileOrFolder.isNote and not fileOrFolder.hide %}
<div @click.stop class="notelink {{ 'active-note' if fileOrFolder.permalink === permalink}}">
<a data-note-icon="{{fileOrFolder.noteIcon}}" style="text-decoration: none;" class="filename" href="{{fileOrFolder.permalink}}">{{fileOrFolder.name}} </a>
<a data-note-icon="{{fileOrFolder.noteIcon}}" style="text-decoration: none;" class="filename" href="{{fileOrFolder.permalink}}">{{fileOrFolder.name}}</a>
</div>
{% elif fileOrFolder.isFolder%}
<div class="folder inner-folder" x-data="{isOpen: $persist(false).as({{currentPath | dump}})}" @click.stop="isOpen=!isOpen">
<div class="foldername-wrapper align-icon">
<i x-show="isOpen" style="display: none;" data-lucide="chevron-down"></i>
<i x-show="!isOpen" data-lucide="chevron-right"></i>
<span class="foldername">{{fileOrFolderName}}</span>
<i x-show="isOpen" style="display: none;" data-lucide="chevron-down"></i>
<i x-show="!isOpen" data-lucide="chevron-right"></i>
{% if fileOrFolder.folderNote %}
<a @click.stop class="filename" href="{{fileOrFolder.folderNote.permalink}}">{{fileOrFolderName}}</a>
{% else %}
<span class="foldername">{{fileOrFolderName}}</span>
{% endif %}
</div>
{% for fileOrFolderName, child in fileOrFolder %}
{{menuItem(fileOrFolderName, child, step+1, (currentPath+"/"+fileOrFolderName))}}
Expand All @@ -20,15 +24,15 @@
</div>
{%endif%}
{% endmacro %}

<div x-init="isDesktop = (window.innerWidth>=1000) ? true: false;"
x-on:resize.window="isDesktop = (window.innerWidth>=1000) ? true : false;"
x-data="{isDesktop: true, showFilesMobile: false}">

<div x-show.important="!isDesktop" style="display: none;">
{%include "components/filetreeNavbar.njk"%}
</div>

<div x-show="showFilesMobile && !isDesktop" @click="showFilesMobile = false" style="display:none;" class="fullpage-overlay"></div>

<div class="filetree-wrapper" x-show.important="isDesktop || showFilesMobile" style="display: none;">
Expand Down