From: Adam Dullage Date: Fri, 4 Apr 2025 11:37:13 +0000 (+0100) Subject: Enhance tag link auto parsing to sort by title X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=9d75c370f9a01944506d94e1b2c1a29dd920e475;p=flatnotes.git Enhance tag link auto parsing to sort by title --- diff --git a/client/components/toastui/extendedAutolinks.js b/client/components/toastui/extendedAutolinks.js index 3a7510e..7e2c73f 100644 --- a/client/components/toastui/extendedAutolinks.js +++ b/client/components/toastui/extendedAutolinks.js @@ -1,3 +1,5 @@ +import { params, searchSortOptions } from "../../constants.js"; + import router from "../../router.js"; /* @@ -90,21 +92,32 @@ function parseWikiLink(source) { } function parseTagLink(source) { - const matched = source.matchAll(/(?:^|\s)(#[a-zA-Z0-9_-]+)(?=\s|$)/g); - if (matched) { - return Array.from(matched).map((match) => { - const text = match[1]; - return { - text, - range: [match.index + match[0].indexOf(text), match.index + match[0].indexOf(text) + text.length - 1], - url: `${router.resolve({ name: "search", query: { term: text } }).href}`, - }; - }); - } - - return null; + const matched = source.matchAll(/(?:^|\s)(#[a-zA-Z0-9_-]+)(?=\s|$)/g); + if (matched) { + return Array.from(matched).map((match) => { + const text = match[1]; + return { + text, + range: [ + match.index + match[0].indexOf(text), + match.index + match[0].indexOf(text) + text.length - 1, + ], + url: `${ + router.resolve({ + name: "search", + query: { + [params.searchTerm]: text, + [params.sortBy]: searchSortOptions.title, + }, + }).href + }`, + }; + }); } + return null; +} + function extendedAutolinks(source) { return [ ...parseUrlLink(source),