@@ -70,7 +70,7 @@ function getPermalinkMeta(note, key) {
7070 }
7171 if ( note . data . tags && note . data . tags . indexOf ( "gardenEntry" ) != - 1 ) {
7272 permalink = "/" ;
73- }
73+ }
7474 if ( note . data . title ) {
7575 name = note . data . title ;
7676 }
@@ -112,12 +112,36 @@ function assignNested(obj, keyPath, value) {
112112 obj [ keyPath [ lastKeyIndex ] ] = value ;
113113}
114114
115+ /**
116+ * A folder note is a note with the same filename as the parent folder.
117+ * Hide the folder note and link to it from the folder to treat it as a special case.
118+ *
119+ * @returns {void }
120+ */
121+ function detectFoldersWithFolderNotes ( tree ) {
122+ for ( const [ fileOrFolderName , fileOrFolder ] of Object . entries ( tree ) ) {
123+ if ( fileOrFolder . isFolder ) {
124+ // Check if any of the children are notes with the same name
125+ for ( const [ childName , child ] of Object . entries ( fileOrFolder ) ) {
126+ if ( child . isNote && childName === ( fileOrFolderName + ".md" ) ) {
127+ // Found, hide the standalone note
128+ child . hide = true ;
129+ fileOrFolder . folderNote = child
130+ } else if ( child . isFolder ) {
131+ detectFoldersWithFolderNotes ( child ) ;
132+ }
133+ }
134+ }
135+ }
136+ }
137+
115138function getFileTree ( data ) {
116139 const tree = { } ;
117140 ( data . collections . note || [ ] ) . forEach ( ( note ) => {
118141 const [ meta , folders ] = getPermalinkMeta ( note ) ;
119142 assignNested ( tree , folders , { isNote : true , ...meta } ) ;
120143 } ) ;
144+ detectFoldersWithFolderNotes ( tree ) ;
121145 const fileTree = sortTree ( tree ) ;
122146 return fileTree ;
123147}
0 commit comments