Browse Source

fix: use ldb/get-built-in-page to get Library

To avoid get another page with the same title.
Tienson Qin 9 months ago
parent
commit
b9fedf2eb9

+ 6 - 0
deps/db/src/logseq/db.cljs

@@ -243,6 +243,12 @@
         (d/entity db [:block/uuid id])
         (d/entity db [:block/uuid id])
         (d/entity db (get-first-page-by-name db (name page-id-name-or-uuid)))))))
         (d/entity db (get-first-page-by-name db (name page-id-name-or-uuid)))))))
 
 
+(defn get-built-in-page
+  [db title]
+  (when db
+    (let [id (common-uuid/gen-uuid :builtin-block-uuid title)]
+      (d/entity db [:block/uuid id]))))
+
 (defn get-case-page
 (defn get-case-page
   "Case sensitive version of get-page. For use with DB graphs"
   "Case sensitive version of get-page. For use with DB graphs"
   [db page-name-or-uuid]
   [db page-name-or-uuid]

+ 1 - 1
deps/db/src/logseq/db/sqlite/create_graph.cljs

@@ -128,7 +128,7 @@
      :properties (filter entity-util/property? properties-tx)}))
      :properties (filter entity-util/property? properties-tx)}))
 
 
 (def built-in-pages-names
 (def built-in-pages-names
-  #{"Contents" "Library"})
+  #{"Library"})
 
 
 (defn- validate-tx-for-duplicate-idents [tx]
 (defn- validate-tx-for-duplicate-idents [tx]
   (when-let [conflicting-idents
   (when-let [conflicting-idents

+ 4 - 4
deps/db/src/logseq/db/sqlite/util.cljs

@@ -104,11 +104,11 @@
 
 
 (defn build-new-page
 (defn build-new-page
   "Builds a basic page to be transacted. A minimal version of gp-block/page-name->map"
   "Builds a basic page to be transacted. A minimal version of gp-block/page-name->map"
-  [page-name]
+  [title]
   (block-with-timestamps
   (block-with-timestamps
-   {:block/name (common-util/page-name-sanity-lc page-name)
-    :block/title page-name
-    :block/uuid (common-uuid/gen-uuid :builtin-block-uuid page-name)
+   {:block/name (common-util/page-name-sanity-lc title)
+    :block/title title
+    :block/uuid (common-uuid/gen-uuid :builtin-block-uuid title)
     :block/tags #{:logseq.class/Page}}))
     :block/tags #{:logseq.class/Page}}))
 
 
 (defn kv
 (defn kv

+ 1 - 3
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -367,9 +367,7 @@
 (defn page-with-parent-and-order
 (defn page-with-parent-and-order
   "Apply to namespace pages"
   "Apply to namespace pages"
   [db page & {:keys [parent]}]
   [db page & {:keys [parent]}]
-  ;; FIXME: using db/ident instead of page title because users can create pages
-  ;; with the same name
-  (let [library (ldb/get-page db "Library")]
+  (let [library (ldb/get-built-in-page db "Library")]
     (when (nil? library)
     (when (nil? library)
       (throw (ex-info "Library page doesn't exist" {})))
       (throw (ex-info "Library page doesn't exist" {})))
     (assoc page
     (assoc page