mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	not generating externalLink labels anymore since there can be too many and benefit is too small
This commit is contained in:
		| @@ -812,10 +812,8 @@ class Note extends Entity { | |||||||
|             FROM attributes  |             FROM attributes  | ||||||
|             WHERE noteId = ? AND  |             WHERE noteId = ? AND  | ||||||
|                   isDeleted = 0 AND |                   isDeleted = 0 AND | ||||||
|                   ((type = 'relation' AND  |                   type = 'relation' AND | ||||||
|                     name IN ('internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink')) |                   name IN ('internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink')`, [this.noteId]); | ||||||
|                   OR |  | ||||||
|                    (type = 'label' AND name = 'externalLink'))`, [this.noteId]); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -69,19 +69,7 @@ export default class AttributesWidget extends CollapsibleWidget { | |||||||
|     async renderAttributes(attributes, $container) { |     async renderAttributes(attributes, $container) { | ||||||
|         for (const attribute of attributes) { |         for (const attribute of attributes) { | ||||||
|             if (attribute.type === 'label') { |             if (attribute.type === 'label') { | ||||||
|                 if (attribute.name === 'externalLink') { |  | ||||||
|                     $container.append('@' + attribute.name + "="); |  | ||||||
|                     $container.append( |  | ||||||
|                         $('<a>') |  | ||||||
|                             .text(attribute.value) |  | ||||||
|                             .attr('href', attribute.value) |  | ||||||
|                             .addClass('external') |  | ||||||
|                     ); |  | ||||||
|                     $container.append(" "); |  | ||||||
|                 } |  | ||||||
|                 else { |  | ||||||
|                 $container.append(utils.formatLabel(attribute) + " "); |                 $container.append(utils.formatLabel(attribute) + " "); | ||||||
|                 } |  | ||||||
|             } else if (attribute.type === 'relation') { |             } else if (attribute.type === 'relation') { | ||||||
|                 if (attribute.value) { |                 if (attribute.value) { | ||||||
|                     $container.append('@' + attribute.name + "="); |                     $container.append('@' + attribute.name + "="); | ||||||
|   | |||||||
| @@ -152,11 +152,6 @@ async function importTar(taskContext, fileBuffer, importRootNote) { | |||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (attr.type === 'label' && attr.name === 'externalLink') { |  | ||||||
|                 // also created automatically |  | ||||||
|                 continue; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (attr.type === 'relation') { |             if (attr.type === 'relation') { | ||||||
|                 attr.value = getNewNoteId(attr.value); |                 attr.value = getNewNoteId(attr.value); | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -154,11 +154,6 @@ async function importZip(taskContext, fileBuffer, importRootNote) { | |||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (attr.type === 'label' && attr.name === 'externalLink') { |  | ||||||
|                 // also created automatically |  | ||||||
|                 continue; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (attr.type === 'relation') { |             if (attr.type === 'relation') { | ||||||
|                 attr.value = getNewNoteId(attr.value); |                 attr.value = getNewNoteId(attr.value); | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -225,20 +225,6 @@ function findInternalLinks(content, foundLinks) { | |||||||
|     return content.replace(/href="[^"]*#root/g, 'href="#root'); |     return content.replace(/href="[^"]*#root/g, 'href="#root'); | ||||||
| } | } | ||||||
|  |  | ||||||
| function findExternalLinks(content, foundLinks) { |  | ||||||
|     const re = /href="([a-zA-Z]+:\/\/[^"]*)"/g; |  | ||||||
|     let match; |  | ||||||
|  |  | ||||||
|     while (match = re.exec(content)) { |  | ||||||
|         foundLinks.push({ |  | ||||||
|             name: 'externalLink', |  | ||||||
|             value: match[1] |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     return content; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function findIncludeNoteLinks(content, foundLinks) { | function findIncludeNoteLinks(content, foundLinks) { | ||||||
|     const re = /<section class="include-note" data-note-id="([a-zA-Z0-9]+)">/g; |     const re = /<section class="include-note" data-note-id="([a-zA-Z0-9]+)">/g; | ||||||
|     let match; |     let match; | ||||||
| @@ -392,7 +378,6 @@ async function saveLinks(note, content) { | |||||||
|     if (note.type === 'text') { |     if (note.type === 'text') { | ||||||
|         content = findImageLinks(content, foundLinks); |         content = findImageLinks(content, foundLinks); | ||||||
|         content = findInternalLinks(content, foundLinks); |         content = findInternalLinks(content, foundLinks); | ||||||
|         content = findExternalLinks(content, foundLinks); |  | ||||||
|         content = findIncludeNoteLinks(content, foundLinks); |         content = findIncludeNoteLinks(content, foundLinks); | ||||||
|  |  | ||||||
|         content = await downloadImages(note.noteId, content); |         content = await downloadImages(note.noteId, content); | ||||||
| @@ -407,12 +392,10 @@ 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) { | ||||||
|         if (foundLink.name !== 'externalLink') { |  | ||||||
|         const targetNote = await repository.getNote(foundLink.value); |         const targetNote = await repository.getNote(foundLink.value); | ||||||
|         if (!targetNote || targetNote.isDeleted) { |         if (!targetNote || targetNote.isDeleted) { | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|         } |  | ||||||
|  |  | ||||||
|         const existingLink = existingLinks.find(existingLink => |         const existingLink = existingLinks.find(existingLink => | ||||||
|             existingLink.value === foundLink.value |             existingLink.value === foundLink.value | ||||||
| @@ -421,7 +404,7 @@ async function saveLinks(note, content) { | |||||||
|         if (!existingLink) { |         if (!existingLink) { | ||||||
|             const newLink = await new Attribute({ |             const newLink = await new Attribute({ | ||||||
|                 noteId: note.noteId, |                 noteId: note.noteId, | ||||||
|                 type: foundLink.name === 'externalLink' ? 'label' : 'relation', |                 type: 'relation', | ||||||
|                 name: foundLink.name, |                 name: foundLink.name, | ||||||
|                 value: foundLink.value, |                 value: foundLink.value, | ||||||
|             }).save(); |             }).save(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user