Переглянути джерело

fix: import bug with aliased namespace pages

Was also failing docs graph. Part of logseq/db-test#136 and part of
LOG-3230
Gabriel Horner 1 рік тому
батько
коміт
90d1b7261f

+ 7 - 4
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -655,6 +655,7 @@
                                 {:block/uuid (get-page-uuid page-names-to-uuids (get-in block' [:block/namespace :block/name]))}
                                 ;; DB graphs only have child name of namespace
                                 :block/title new-title
+                                ::original-name (:block/name block')
                                 :block/name (common-util/page-name-sanity-lc new-title)})))
                   block')]
     {:block block'' :properties-tx properties-tx}))
@@ -893,13 +894,15 @@
         all-pages-m (mapv #(handle-page-properties % @conn page-names-to-uuids all-pages options)
                           all-pages)
         pages-tx (keep (fn [m]
-                         (if-let [page-uuid (all-existing-page-uuids (:block/name m))]
-                           (build-existing-page m @conn page-uuid page-names-to-uuids options)
+                         (if-let [page-uuid (if (::original-name m)
+                                              (all-existing-page-uuids (::original-name m))
+                                              (all-existing-page-uuids (:block/name m)))]
+                           (build-existing-page (dissoc m ::original-name) @conn page-uuid page-names-to-uuids options)
                            (when (or (= "class" (:block/type m))
                                      ;; Don't build a new page if it overwrites an existing class
                                      (not (some-> (get @(:all-idents import-state) (keyword (:block/title m)))
                                                   db-malli-schema/class?)))
-                             (build-new-page-or-class m @conn tag-classes page-names-to-uuids (:all-idents import-state)))))
+                             (build-new-page-or-class (dissoc m ::original-name) @conn tag-classes page-names-to-uuids (:all-idents import-state)))))
                        (map :block all-pages-m))]
     {:pages-tx pages-tx
      :page-properties-tx (mapcat :properties-tx all-pages-m)
@@ -1360,7 +1363,7 @@
                           (filter #(contains? #{"md" "org" "markdown" "edn"} (path/file-ext (:path %)))))
            asset-files (filter #(string/starts-with? (get % rpath-key) "assets/") files)
            doc-options (build-doc-options config options)]
-       (log-fn "Importing" (count files) "files ...")
+       (log-fn "Importing" (count doc-files) "files ...")
        ;; These export* fns are all the major export/import steps
        (p/do!
         (export-logseq-files repo-or-conn (filter logseq-file? files) <read-file

+ 1 - 1
deps/graph-parser/test/resources/exporter-test-graph/journals/2024_10_17.md

@@ -1,5 +1,5 @@
 - test namespaces
-	- [[n1/x/y]]
+	- [[y]]
 	- [[n1/x/z]]
 	- [[n2/x/z]]
 	- [[n2/alias]] tests name that overlaps with built-in ones

+ 3 - 0
deps/graph-parser/test/resources/exporter-test-graph/pages/n1___x___y.md

@@ -1 +1,4 @@
+alias:: y
+description:: page property triggers aliased namespace bug
+
 - some content