Skip to content

Build your personal knowledge base with Trilium Notes

experimental hiding of images if they are included in the parent note

zadam576958730531
diff --git a/src/public/app/services/tree_builder.js b/src/public/app/services/tree_builder.js
index ac267c475a..ddb90aeb70 100644
--- a/src/public/app/services/tree_builder.js
+++ b/src/public/app/services/tree_builder.js
@@ -98,9 +98,8 @@ async function prepareNode(branch) {
key: utils.randomString(12) // this should prevent some "duplicate key" errors
};
- if (note.hasChildren() || note.type === 'search') {
- node.folder = true;
- }
+ node.folder = getChildBranchesWithoutImages(note).length > 0
+ || note.type === 'search';
return node;
}
@@ -108,16 +107,9 @@ async function prepareNode(branch) {
async function prepareRealBranch(parentNote) {
utils.assertArguments(parentNote);
- const childBranches = await parentNote.getChildBranches();
-
- if (!childBranches) {
- ws.logError(`No children for ${parentNote}. This shouldn't happen.`);
- return;
- }
-
const noteList = [];
- for (const branch of childBranches) {
+ for (const branch of getChildBranchesWithoutImages(parentNote)) {
const node = await prepareNode(branch);
noteList.push(node);
@@ -126,6 +118,20 @@ async function prepareRealBranch(parentNote) {
return noteList;
}
+function getChildBranchesWithoutImages(parentNote) {
+ const childBranches = parentNote.getChildBranches();
+
+ if (!childBranches) {
+ ws.logError(`No children for ${parentNote}. This shouldn't happen.`);
+ return;
+ }
+
+ const imageLinks = parentNote.getRelations('imageLink');
+
+ // image is already visible in the parent note so no need to display it separately in the book
+ return childBranches.filter(branch => !imageLinks.find(rel => rel.value === branch.noteId));
+}
+
async function prepareSearchBranch(note) {
await treeCache.reloadNotes([note.noteId]);
@@ -170,5 +176,6 @@ export default {
prepareRootNode,
prepareBranch,
getExtraClasses,
- getIcon
+ getIcon,
+ getChildBranchesWithoutImages
}
\ No newline at end of file
diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js
index 368da74254..a6600cff99 100644
--- a/src/public/app/widgets/note_tree.js
+++ b/src/public/app/widgets/note_tree.js
@@ -389,7 +389,8 @@ export default class NoteTreeWidget extends TabAwareWidget {
node.data.isProtected = note.isProtected;
node.data.noteType = note.type;
- node.folder = note.type === 'search' || note.getChildNoteIds().length > 0;
+ node.folder = treeBuilder.getChildBranchesWithoutImages(note).length > 0
+ || note.type === 'search';
node.icon = treeBuilder.getIcon(note);
node.extraClasses = treeBuilder.getExtraClasses(note);
node.title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title;
@@ -481,6 +482,15 @@ export default class NoteTreeWidget extends TabAwareWidget {
// missing handling of things inherited from template
noteIdsToReload.add(attr.noteId);
}
+ else if (attr.type === 'relation' && attr.name === 'imageLink') {
+ const note = treeCache.getNoteFromCache(attr.noteId);
+
+ if (note && note.getChildNoteIds().includes(attr.value)) {
+ // there's new/deleted imageLink betwen note and its image child - which can show/hide
+ // the image (if there is a imageLink relation between parent and child then it is assumed to be "contained" in the note and thus does not have to be displayed in the tree)
+ noteIdsToReload.add(attr.noteId);
+ }
+ }
}
for (const branch of loadResults.getBranches()) {