Enhance tag link auto parsing to sort by title
authorAdam Dullage <redacted>
Fri, 4 Apr 2025 11:37:13 +0000 (12:37 +0100)
committerAdam Dullage <redacted>
Fri, 4 Apr 2025 11:37:13 +0000 (12:37 +0100)
client/components/toastui/extendedAutolinks.js

index 3a7510ebc96fdf39f3eee99486fdc4cfe716eac9..7e2c73f214b36dcbd517c2db406b996a86a52fce 100644 (file)
@@ -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),
git clone https://git.99rst.org/PROJECT