Quellcode durchsuchen

fix: two bugs with updating tags during import

fixes LOG-3073
Gabriel Horner vor 1 Jahr
Ursprung
Commit
b34325be77

+ 1 - 1
deps/db/src/logseq/db/frontend/content.cljs

@@ -98,4 +98,4 @@
                           (:block/uuid tag)
                           page-ref/right-brackets)))
    content
-   tags))
+   (sort-by :block/original-name > tags)))

+ 11 - 0
deps/db/test/logseq/db/frontend/content_test.cljs

@@ -0,0 +1,11 @@
+(ns logseq.db.frontend.content-test
+  (:require [cljs.test :refer [deftest is testing]]
+            [logseq.db.frontend.content :as db-content]))
+
+(deftest replace-tags-with-page-refs
+  (testing "tags with overlapping names get replaced correctly"
+    (is (= "string [[~^foo]] string2 [[~^foo-bar]]"
+           (db-content/replace-tags-with-page-refs
+            "string #foo string2 #foo-bar"
+            [{:block/original-name "foo" :block/uuid "foo"}
+             {:block/original-name "foo-bar" :block/uuid "foo-bar"}])))))

+ 15 - 1
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -14,6 +14,7 @@
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.db :as ldb]
             [logseq.db.frontend.rules :as rules]
+            [logseq.common.util.page-ref :as page-ref]
             [promesa.core :as p]))
 
 (defn- get-pid
@@ -73,13 +74,26 @@
              (throw (ex-info (str "No uuid found for page " (pr-str (:block/name m)))
                              {:page m})))))
 
+(defn- content-without-tags-ignore-case
+  "Ignore case because tags in content can have any case and still have a valid ref"
+  [content tags]
+  (->
+   (reduce
+    (fn [content tag]
+      (-> content
+          (common-util/replace-ignore-case (str "#" tag) "")
+          (common-util/replace-ignore-case (str "#" page-ref/left-brackets tag page-ref/right-brackets) "")))
+    content
+    tags)
+   (string/trim)))
+
 (defn- update-block-tags
   [block tag-classes page-names-to-uuids]
   (if (seq (:block/tags block))
     (let [original-tags (remove :block.temp/new-class (:block/tags block))]
       (-> block
           (update :block/content
-                  db-content/content-without-tags
+                  content-without-tags-ignore-case
                   (->> original-tags
                        (filter #(tag-classes (:block/name %)))
                        (map :block/original-name)))