mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	refactoring of similar notes path handling
This commit is contained in:
		
							parent
							
								
									c8a5c71ec2
								
							
						
					
					
						commit
						c9cc2cb4f3
					
				@ -30,6 +30,25 @@ async function createNoteLink(notePath, noteTitle = null) {
 | 
				
			|||||||
    return noteLink;
 | 
					    return noteLink;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function createNoteLinkWithPath(notePath) {
 | 
				
			||||||
 | 
					    const $link = await createNoteLink(notePath);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const $res = $("<span>").append($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (notePath.includes("/")) {
 | 
				
			||||||
 | 
					        const noteIds = notePath.split("/");
 | 
				
			||||||
 | 
					        noteIds.pop(); // remove last element
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const parentNotePath = noteIds.join("/").trim();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (parentNotePath) {
 | 
				
			||||||
 | 
					            $res.append($("<small>").text(" (" + await treeUtils.getNotePathTitle(parentNotePath) + ")"));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return $res;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getNotePathFromLink($link) {
 | 
					function getNotePathFromLink($link) {
 | 
				
			||||||
    const notePathAttr = $link.attr("data-note-path");
 | 
					    const notePathAttr = $link.attr("data-note-path");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -159,6 +178,7 @@ $(document).on('mousedown', 'span.ck-button__label', e => {
 | 
				
			|||||||
export default {
 | 
					export default {
 | 
				
			||||||
    getNotePathFromUrl,
 | 
					    getNotePathFromUrl,
 | 
				
			||||||
    createNoteLink,
 | 
					    createNoteLink,
 | 
				
			||||||
 | 
					    createNoteLinkWithPath,
 | 
				
			||||||
    addLinkToEditor,
 | 
					    addLinkToEditor,
 | 
				
			||||||
    addTextToEditor,
 | 
					    addTextToEditor,
 | 
				
			||||||
    goToLink
 | 
					    goToLink
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@ import linkService from "../services/link.js";
 | 
				
			|||||||
import server from "../services/server.js";
 | 
					import server from "../services/server.js";
 | 
				
			||||||
import treeCache from "../services/tree_cache.js";
 | 
					import treeCache from "../services/tree_cache.js";
 | 
				
			||||||
import treeUtils from "../services/tree_utils.js";
 | 
					import treeUtils from "../services/tree_utils.js";
 | 
				
			||||||
 | 
					import treeService from "../services/tree.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SimilarNotesWidget extends StandardWidget {
 | 
					class SimilarNotesWidget extends StandardWidget {
 | 
				
			||||||
    getWidgetTitle() { return "Similar notes"; }
 | 
					    getWidgetTitle() { return "Similar notes"; }
 | 
				
			||||||
@ -19,18 +20,20 @@ class SimilarNotesWidget extends StandardWidget {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        await treeCache.getNotes(similarNotes.map(note => note.noteId)); // preload all at once
 | 
					        await treeCache.getNotes(similarNotes.map(note => note.noteId)); // preload all at once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const $list = $('<ul style="padding-left: 20px;">');
 | 
					        const $list = $('<ul>');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const similarNote of similarNotes) {
 | 
					        for (const similarNote of similarNotes) {
 | 
				
			||||||
            const $item = $("<li>")
 | 
					            const note = await treeCache.getNote(similarNote.noteId);
 | 
				
			||||||
                .append(await linkService.createNoteLink(similarNote.notePath.join("/")));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            similarNote.notePath.pop(); // remove last noteId since it's already in the link
 | 
					            if (!note) {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
            if (similarNote.notePath.length > 0) {
 | 
					 | 
				
			||||||
                $item.append($("<small>").text(" (" + await treeUtils.getNotePathTitle(similarNote.notePath.join("/")) + ")"));
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const notePath = await treeService.getSomeNotePath(note);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const $item = $("<li>")
 | 
				
			||||||
 | 
					                .append(await linkService.createNoteLinkWithPath(notePath));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $list.append($item);
 | 
					            $list.append($item);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -392,6 +392,11 @@ body {
 | 
				
			|||||||
    border: 0;
 | 
					    border: 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.note-detail-sidebar .card-body ul {
 | 
				
			||||||
 | 
					    padding-left: 25px;
 | 
				
			||||||
 | 
					    margin-bottom: 5px;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#widgets-configuration {
 | 
					#widgets-configuration {
 | 
				
			||||||
    margin: 0;
 | 
					    margin: 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -348,7 +348,7 @@ function evaluateSimilarity(text1, text2, noteId, results) {
 | 
				
			|||||||
            coeff -= 0.2; // archived penalization
 | 
					            coeff -= 0.2; // archived penalization
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        results.push({coeff, notePath, noteId});
 | 
					        results.push({coeff, noteId});
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user