mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	using included note should create a relation, closes #820
This commit is contained in:
		| @@ -805,7 +805,7 @@ class Note extends Entity { | ||||
|             WHERE noteId = ? AND  | ||||
|                   isDeleted = 0 AND  | ||||
|                   type = 'relation' AND  | ||||
|                   name IN ('internalLink', 'imageLink', 'relationMapLink')`, [this.noteId]); | ||||
|                   name IN ('internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink')`, [this.noteId]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -147,7 +147,7 @@ async function importTar(taskContext, fileBuffer, importRootNote) { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             if (attr.type === 'relation' && ['internalLink', 'imageLink', 'relationMapLink'].includes(attr.name)) { | ||||
|             if (attr.type === 'relation' && ['internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink'].includes(attr.name)) { | ||||
|                 // these relations are created automatically and as such don't need to be duplicated in the import | ||||
|                 continue; | ||||
|             } | ||||
|   | ||||
| @@ -242,6 +242,20 @@ function findInternalLinks(content, foundLinks) { | ||||
|     return content.replace(/href="[^"]*#root/g, 'href="#root'); | ||||
| } | ||||
|  | ||||
| function findIncludeNoteLinks(content, foundLinks) { | ||||
|     const re = /<section class="include-note" data-note-id="([a-zA-Z0-9]+)">/g; | ||||
|     let match; | ||||
|  | ||||
|     while (match = re.exec(content)) { | ||||
|         foundLinks.push({ | ||||
|             name: 'includeNoteLink', | ||||
|             value: match[1] | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     return content; | ||||
| } | ||||
|  | ||||
| function findRelationMapLinks(content, foundLinks) { | ||||
|     const obj = JSON.parse(content); | ||||
|  | ||||
| @@ -263,10 +277,11 @@ async function saveLinks(note, content) { | ||||
|     } | ||||
|  | ||||
|     const foundLinks = []; | ||||
|  | ||||
| console.log("Scanning", content); | ||||
|     if (note.type === 'text') { | ||||
|         content = findImageLinks(content, foundLinks); | ||||
|         content = findInternalLinks(content, foundLinks); | ||||
|         content = findIncludeNoteLinks(content, foundLinks); | ||||
|     } | ||||
|     else if (note.type === 'relation-map') { | ||||
|         findRelationMapLinks(content, foundLinks); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user