mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	exported links to "named" notes should be preserved upon import
This commit is contained in:
		| @@ -170,10 +170,15 @@ async function loadReferenceLinkTitle(noteId, $el) { | |||||||
|         title = note.isDeleted ? `${note.title} (deleted)` : note.title; |         title = note.isDeleted ? `${note.title} (deleted)` : note.title; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     $el.addClass(note.getColorClass()); |     if (note) { | ||||||
|  |         $el.addClass(note.getColorClass()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     $el.text(title); |     $el.text(title); | ||||||
|  |  | ||||||
|     $el.prepend($("<span>").addClass(note.getIcon())); |     if (note) { | ||||||
|  |         $el.prepend($("<span>").addClass(note.getIcon())); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| $(document).on('click', "a", goToLink); | $(document).on('click', "a", goToLink); | ||||||
|   | |||||||
| @@ -361,12 +361,16 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async createNoteForReferenceLink(title) { |     async createNoteForReferenceLink(title) { | ||||||
|         const {note} = await noteCreateService.createNoteWithTypePrompt(this.notePath, { |         const resp = await noteCreateService.createNoteWithTypePrompt(this.notePath, { | ||||||
|             activate: false, |             activate: false, | ||||||
|             title: title |             title: title | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         return treeService.getSomeNotePath(note); |         if (!resp) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return treeService.getSomeNotePath(resp.note); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async refreshIncludedNoteEvent({noteId}) { |     async refreshIncludedNoteEvent({noteId}) { | ||||||
|   | |||||||
| @@ -432,7 +432,18 @@ ${markdownContent}`; | |||||||
|  |  | ||||||
|     for (const noteMeta of Object.values(noteIdToMeta)) { |     for (const noteMeta of Object.values(noteIdToMeta)) { | ||||||
|         // filter out relations which are not inside this export |         // 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 |     if (!rootMeta) { // corner case of disabled export for exported note | ||||||
|   | |||||||
| @@ -39,6 +39,11 @@ async function importZip(taskContext, fileBuffer, importRootNote) { | |||||||
|             return ""; |             return ""; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if (origNoteId === 'root' || origNoteId.startsWith("_")) { | ||||||
|  |             // these "named" noteIds don't differ between Trilium instances | ||||||
|  |             return origNoteId; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         if (!noteIdMap[origNoteId]) { |         if (!noteIdMap[origNoteId]) { | ||||||
|             noteIdMap[origNoteId] = utils.newEntityId(); |             noteIdMap[origNoteId] = utils.newEntityId(); | ||||||
|         } |         } | ||||||
| @@ -318,7 +323,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) { | |||||||
|                     return `href="${url}"`; |                     return `href="${url}"`; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 if (isUrlAbsolute(url)) { |                 if (url.startsWith('#') || isUrlAbsolute(url)) { | ||||||
|                     return match; |                     return match; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| @@ -330,7 +335,13 @@ async function importZip(taskContext, fileBuffer, importRootNote) { | |||||||
|             content = content.replace(/data-note-path="([^"]*)"/g, (match, notePath) => { |             content = content.replace(/data-note-path="([^"]*)"/g, (match, notePath) => { | ||||||
|                 const noteId = notePath.split("/").pop(); |                 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}"`; |                 return `data-note-path="root/${targetNoteId}"`; | ||||||
|             }); |             }); | ||||||
|   | |||||||
| @@ -26,7 +26,12 @@ class SearchResult { | |||||||
|  |  | ||||||
|         // add one more time for note title alone (already contained in the notePathTitle), |         // 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 |         // 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) { |     addScoreForStrings(tokens, str, factor) { | ||||||
|   | |||||||
| @@ -151,9 +151,6 @@ function findResultsWithExpression(expression, searchContext) { | |||||||
|         noteIdToNotePath: {} |         noteIdToNotePath: {} | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     const ancestorNote = becca.getNote(searchContext.ancestorNoteId || 'root'); |  | ||||||
|     const showNotesInHiddenSubtree = ancestorNote.hasAncestor('_hidden'); |  | ||||||
|  |  | ||||||
|     const noteSet = expression.execute(allNoteSet, executionContext, searchContext); |     const noteSet = expression.execute(allNoteSet, executionContext, searchContext); | ||||||
|  |  | ||||||
|     const searchResults = noteSet.notes |     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())}`); |                 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); |             return new SearchResult(notePathArray); | ||||||
|         }) |         }) | ||||||
|         .filter(note => !!note); |         .filter(note => !!note); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user