mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	importing a note now creates internal link relations
This commit is contained in:
		| @@ -250,7 +250,7 @@ ${content} | |||||||
|         if (noteMeta.isClone) { |         if (noteMeta.isClone) { | ||||||
|             const targetUrl = getTargetUrl(noteMeta.noteId, noteMeta); |             const targetUrl = getTargetUrl(noteMeta.noteId, noteMeta); | ||||||
|  |  | ||||||
|             let content = `<p>This is a clone of a note. Go to its <a href="${targetUrl}">primary location</a>.</p>`; |             let content = `<p>This is a clone of a note. Go to its <a href="${encodeURIComponent(targetUrl)}">primary location</a>.</p>`; | ||||||
|  |  | ||||||
|             content = prepareContent(noteMeta.title, content, noteMeta); |             content = prepareContent(noteMeta.title, content, noteMeta); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -429,7 +429,11 @@ async function importTar(importContext, fileBuffer, importRootNote) { | |||||||
|             const createdNoteIds = {}; |             const createdNoteIds = {}; | ||||||
|  |  | ||||||
|             for (const path in createdPaths) { |             for (const path in createdPaths) { | ||||||
|                 createdNoteIds[createdPaths[path]] = true; |                 const noteId = createdPaths[path]; | ||||||
|  |  | ||||||
|  |                 createdNoteIds[noteId] = true; | ||||||
|  |  | ||||||
|  |                 await noteService.scanForLinks(noteId); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // we're saving attributes and links only now so that all relation and link target notes |             // we're saving attributes and links only now so that all relation and link target notes | ||||||
|   | |||||||
| @@ -271,6 +271,11 @@ async function saveLinks(note, content) { | |||||||
|     const existingLinks = await note.getLinks(); |     const existingLinks = await note.getLinks(); | ||||||
|  |  | ||||||
|     for (const foundLink of foundLinks) { |     for (const foundLink of foundLinks) { | ||||||
|  |         const targetNote = await repository.getNote(foundLink.value); | ||||||
|  |         if (!targetNote || targetNote.isDeleted) { | ||||||
|  |             continue; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         const existingLink = existingLinks.find(existingLink => |         const existingLink = existingLinks.find(existingLink => | ||||||
|             existingLink.value === foundLink.value |             existingLink.value === foundLink.value | ||||||
|             && existingLink.name === foundLink.name); |             && existingLink.name === foundLink.name); | ||||||
| @@ -422,6 +427,18 @@ async function deleteNote(branch) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | async function scanForLinks(noteId) { | ||||||
|  |     const note = await repository.getNote(noteId); | ||||||
|  |     if (!note || !['text', 'relation-map'].includes(note.type)) { | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     const content = await note.getContent(); | ||||||
|  |     const newContent = await saveLinks(note, content); | ||||||
|  |  | ||||||
|  |     await note.setContent(newContent); | ||||||
|  | } | ||||||
|  |  | ||||||
| async function cleanupDeletedNotes() { | async function cleanupDeletedNotes() { | ||||||
|     const cutoffDate = new Date(Date.now() - 48 * 3600 * 1000); |     const cutoffDate = new Date(Date.now() - 48 * 3600 * 1000); | ||||||
|  |  | ||||||
| @@ -445,5 +462,6 @@ module.exports = { | |||||||
|     createNote, |     createNote, | ||||||
|     updateNote, |     updateNote, | ||||||
|     deleteNote, |     deleteNote, | ||||||
|     protectNoteRecursively |     protectNoteRecursively, | ||||||
|  |     scanForLinks | ||||||
| }; | }; | ||||||
		Reference in New Issue
	
	Block a user