exported links to "named" notes should be preserved upon import

This commit is contained in:
zadam 2022-12-23 23:08:30 +01:00
parent 5ae0a5cf1e
commit 392b89e6dd
6 changed files with 44 additions and 15 deletions

View file

@ -170,10 +170,15 @@ async function loadReferenceLinkTitle(noteId, $el) {
title = note.isDeleted ? `${note.title} (deleted)` : note.title;
}
$el.addClass(note.getColorClass());
if (note) {
$el.addClass(note.getColorClass());
}
$el.text(title);
$el.prepend($("<span>").addClass(note.getIcon()));
if (note) {
$el.prepend($("<span>").addClass(note.getIcon()));
}
}
$(document).on('click', "a", goToLink);

View file

@ -361,12 +361,16 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
}
async createNoteForReferenceLink(title) {
const {note} = await noteCreateService.createNoteWithTypePrompt(this.notePath, {
const resp = await noteCreateService.createNoteWithTypePrompt(this.notePath, {
activate: false,
title: title
});
return treeService.getSomeNotePath(note);
if (!resp) {
return;
}
return treeService.getSomeNotePath(resp.note);
}
async refreshIncludedNoteEvent({noteId}) {

View file

@ -432,7 +432,18 @@ ${markdownContent}`;
for (const noteMeta of Object.values(noteIdToMeta)) {
// filter out relations which are not inside this export
noteMeta.attributes = noteMeta.attributes.filter(attr => attr.type !== 'relation' || attr.value in noteIdToMeta);
noteMeta.attributes = noteMeta.attributes.filter(attr => {
if (attr.type !== 'relation') {
return true;
} else if (attr.value in noteIdToMeta) {
return true;
} else if (attr.value === 'root' || attr.value?.startsWith("_")) {
// relations to "named" noteIds can be preserved
return true;
} else {
return false;
}
});
}
if (!rootMeta) { // corner case of disabled export for exported note

View file

@ -39,6 +39,11 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
return "";
}
if (origNoteId === 'root' || origNoteId.startsWith("_")) {
// these "named" noteIds don't differ between Trilium instances
return origNoteId;
}
if (!noteIdMap[origNoteId]) {
noteIdMap[origNoteId] = utils.newEntityId();
}
@ -318,7 +323,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
return `href="${url}"`;
}
if (isUrlAbsolute(url)) {
if (url.startsWith('#') || isUrlAbsolute(url)) {
return match;
}
@ -330,7 +335,13 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
content = content.replace(/data-note-path="([^"]*)"/g, (match, notePath) => {
const noteId = notePath.split("/").pop();
const targetNoteId = noteIdMap[noteId];
let targetNoteId;
if (noteId === 'root' || noteId.startsWith("_")) { // named noteIds stay identical across instances
targetNoteId = noteId;
} else {
targetNoteId = noteIdMap[noteId];
}
return `data-note-path="root/${targetNoteId}"`;
});

View file

@ -26,7 +26,12 @@ class SearchResult {
// add one more time for note title alone (already contained in the notePathTitle),
// thus preferring notes with matches on its own note title as opposed to ancestors or descendants
this.addScoreForStrings(tokens, becca.notes[this.noteId].title, 1.5);
const note = becca.notes[this.noteId];
this.addScoreForStrings(tokens, note.title, 1.5);
if (note.isInHiddenSubtree()) {
this.score = this.score / 2;
}
}
addScoreForStrings(tokens, str, factor) {

View file

@ -151,9 +151,6 @@ function findResultsWithExpression(expression, searchContext) {
noteIdToNotePath: {}
};
const ancestorNote = becca.getNote(searchContext.ancestorNoteId || 'root');
const showNotesInHiddenSubtree = ancestorNote.hasAncestor('_hidden');
const noteSet = expression.execute(allNoteSet, executionContext, searchContext);
const searchResults = noteSet.notes
@ -168,10 +165,6 @@ function findResultsWithExpression(expression, searchContext) {
throw new Error(`Can't find note path for note ${JSON.stringify(note.getPojo())}`);
}
if (!showNotesInHiddenSubtree && notePathArray.includes('_hidden')) {
return null;
}
return new SearchResult(notePathArray);
})
.filter(note => !!note);