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

@@ -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}"`;
});