From e7bfd53a7c0ff568681b8204f439de765e8cd81d Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Tue, 27 Jan 2026 15:55:15 -0500 Subject: [PATCH] fix: import of namespace tags w/ 2+ levels of namespaces. This should fix https://github.com/logseq/db-test/issues/679 --- deps/db/src/logseq/db.cljs | 1 + deps/graph-parser/src/logseq/graph_parser/exporter.cljs | 9 ++++++--- .../test/logseq/graph_parser/exporter_test.cljs | 4 ++-- .../resources/exporter-test-graph/journals/2025_12_17.md | 3 ++- .../resources/exporter-test-graph/journals/2026_01_27.md | 1 + 5 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 deps/graph-parser/test/resources/exporter-test-graph/journals/2026_01_27.md diff --git a/deps/db/src/logseq/db.cljs b/deps/db/src/logseq/db.cljs index d3573ebfbe..d14652a471 100644 --- a/deps/db/src/logseq/db.cljs +++ b/deps/db/src/logseq/db.cljs @@ -596,6 +596,7 @@ (def get-all-properties db-db/get-all-properties) (def get-class-extends db-class/get-class-extends) (def get-classes-parents db-db/get-classes-parents) +(def get-page-parents db-db/get-page-parents) (def get-title-with-parents db-db/get-title-with-parents) (def class-instance? db-db/class-instance?) (def inline-tag? db-db/inline-tag?) diff --git a/deps/graph-parser/src/logseq/graph_parser/exporter.cljs b/deps/graph-parser/src/logseq/graph_parser/exporter.cljs index 3a7658941f..e50e0d2ee8 100644 --- a/deps/graph-parser/src/logseq/graph_parser/exporter.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/exporter.cljs @@ -133,9 +133,12 @@ db (ns-util/get-last-part full-name)) (map #(d/entity db %)) - (some #(let [parents (->> (ldb/get-class-extends %) - (remove (fn [e] (= :logseq.class/Root (:db/ident e)))) - vec)] + (some #(let [parent (->> (ldb/get-class-extends %) + (remove (fn [e] (= :logseq.class/Root (:db/ident e)))) + first) + parent-ancestors (when parent (ldb/get-page-parents parent)) + parents (cond-> (or parent-ancestors []) + parent (conj parent))] (when (= full-name (string/join ns-util/namespace-char (map :block/name (conj parents %)))) (:block/uuid %))))) (first diff --git a/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs b/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs index 6585357646..d46b286fd8 100644 --- a/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs +++ b/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs @@ -210,7 +210,7 @@ ;; Counts ;; Includes journals as property values e.g. :logseq.property/deadline - (is (= 31 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Journal]] @conn)))) + (is (= 32 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Journal]] @conn)))) (is (= 5 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Asset]] @conn)))) (is (= 4 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Task]] @conn)))) @@ -231,7 +231,7 @@ #_(map #(select-keys % [:block/title :block/tags])) count)) "Correct number of pages with block content") - (is (= 14 (->> @conn + (is (= 15 (->> @conn (d/q '[:find [?ident ...] :where [?b :block/tags :logseq.class/Tag] [?b :db/ident ?ident] (not [?b :logseq.property/built-in?])]) count)) diff --git a/deps/graph-parser/test/resources/exporter-test-graph/journals/2025_12_17.md b/deps/graph-parser/test/resources/exporter-test-graph/journals/2025_12_17.md index ce10443f60..290877ca98 100644 --- a/deps/graph-parser/test/resources/exporter-test-graph/journals/2025_12_17.md +++ b/deps/graph-parser/test/resources/exporter-test-graph/journals/2025_12_17.md @@ -1,4 +1,5 @@ tags:: #diary - This journal has a tag to test journals with tags - Block tags #p1 - tags:: ai, #block-tag \ No newline at end of file + tags:: ai, #block-tag +- block w/ longer ns tag #n1/n2/n3 \ No newline at end of file diff --git a/deps/graph-parser/test/resources/exporter-test-graph/journals/2026_01_27.md b/deps/graph-parser/test/resources/exporter-test-graph/journals/2026_01_27.md new file mode 100644 index 0000000000..bcaffb0cf6 --- /dev/null +++ b/deps/graph-parser/test/resources/exporter-test-graph/journals/2026_01_27.md @@ -0,0 +1 @@ +- 2nd instance of block w/ longer ns tag #n1/n2/n3 \ No newline at end of file