Quellcode durchsuchen

fix: built-in pages option

also renamed option and fixed a sorting bug
Gabriel Horner vor 7 Monaten
Ursprung
Commit
9b9c22933f

+ 3 - 3
deps/db/script/diff_graphs.cljs

@@ -28,8 +28,8 @@
    :exclude-namespaces {:alias :e
                         :coerce #{}
                         :desc "Namespaces to exclude from properties and classes"}
-   :ignore-built-ins? {:alias :i
-                       :desc "Ignore built-in pages"}
+   :exclude-built-in-pages? {:alias :b
+                             :desc "Exclude built-in pages"}
    :include-timestamps? {:alias :t
                          :desc "Include timestamps in export"}})
 
@@ -42,7 +42,7 @@
             (js/process.exit 1))
         conn (apply sqlite-cli/open-db! (get-dir-and-db-name graph-dir))
         conn2 (apply sqlite-cli/open-db! (get-dir-and-db-name graph-dir2))
-        export-options (select-keys options [:include-timestamps? :exclude-namespaces :ignore-built-ins?])
+        export-options (select-keys options [:include-timestamps? :exclude-namespaces :exclude-built-in-pages?])
         export-map (sqlite-export/build-export @conn {:export-type :graph :graph-options export-options})
         export-map2 (sqlite-export/build-export @conn2 {:export-type :graph :graph-options export-options})
         prepare-export-to-diff

+ 3 - 3
deps/db/script/export_graph.cljs

@@ -39,8 +39,8 @@
    :exclude-namespaces {:alias :e
                         :coerce #{}
                         :desc "Namespaces to exclude from properties and classes"}
-   :ignore-built-ins? {:alias :i
-                       :desc "Ignore built-in pages"}
+   :exclude-built-in-pages? {:alias :b
+                             :desc "Exclude built-in pages"}
    :export-options {:alias :E
                     :desc "Raw options map to pass to export"}})
 
@@ -53,7 +53,7 @@
             (js/process.exit 1))
         [dir db-name] (get-dir-and-db-name graph-dir)
         conn (sqlite-cli/open-db! dir db-name)
-        export-options (merge (select-keys options [:include-timestamps? :exclude-namespaces :ignore-built-ins?])
+        export-options (merge (select-keys options [:include-timestamps? :exclude-namespaces :exclude-built-in-pages?])
                               (edn/read-string (:export-options options)))
         export-map (sqlite-export/build-export @conn {:export-type :graph :graph-options export-options})]
     (if (:file options)

+ 23 - 19
deps/db/src/logseq/db/sqlite/export.cljs

@@ -508,10 +508,15 @@
       (assoc :classes classes))))
 
 (defn- get-graph-content-ref-uuids
-  [db]
-  (let [block-titles (map :v (d/datoms db :avet :block/title))
-        block-links (->> (d/datoms db :avet :block/link)
-                         (map #(:block/uuid (d/entity db (:v %)))))
+  [db {:keys [:exclude-built-in-pages?]}]
+  (let [;; Add support for exclude-built-in-pages? and block-titles as needed
+        block-titles (map :v (d/datoms db :avet :block/title))
+        block-links (if exclude-built-in-pages?
+                      (->> (d/datoms db :avet :block/link)
+                           (keep #(when-not (:logseq.property/built-in? (:block/page (d/entity db (:e %))))
+                                    (:block/uuid (d/entity db (:v %))))))
+                      (->> (d/datoms db :avet :block/link)
+                           (map #(:block/uuid (d/entity db (:v %))))))
         content-ref-uuids (concat (->> block-titles
                                        (filter string?)
                                        (mapcat db-content/get-matched-ids))
@@ -520,26 +525,24 @@
 
 (defn- build-graph-pages-export
   "Handles pages, journals and their blocks"
-  [db graph-ontology options]
-  (let [options (merge options
+  [db graph-ontology options*]
+  (let [options (merge options*
                        {:graph-ontology graph-ontology}
-                       ;; when ontology is incomplete, :closed values can fail so have to build ontology
-                       (when (empty? (:exclude-namespaces options))
+                       ;; dont exclude when ontology is incomplete because :closed values can fail so have to build ontology
+                       (when (empty? (:exclude-namespaces options*))
                          {:exclude-ontology? true}))
         page-ids (concat (map :e (d/datoms db :avet :block/tags :logseq.class/Page))
                          (map :e (d/datoms db :avet :block/tags :logseq.class/Journal)))
         page-exports (mapv (fn [eid]
                              (let [page-blocks* (get-page-blocks db eid)]
-                               ;; TODO: Configure so that no ontologies are exported
                                (build-page-export* db eid page-blocks* (merge options {:include-uuid-fn (constantly true)}))))
                            page-ids)
-        pages-and-blocks* (mapcat :pages-and-blocks page-exports)
-        pages-and-blocks (if (:ignore-built-ins? options)
-                           (vec (remove #(get-in % [:page :build/properties :logseq.property/built-in?])
-                                        pages-and-blocks*))
-                           pages-and-blocks*)
-        pages-export {:pages-and-blocks pages-and-blocks
-                      :pvalue-uuids (set (mapcat :pvalue-uuids page-exports))}]
+        page-exports' (remove (fn [page-export]
+                                (and (:exclude-built-in-pages? options)
+                                     (get-in page-export [:pages-and-blocks 0 :page :build/properties :logseq.property/built-in?])))
+                              page-exports)
+        pages-export {:pages-and-blocks (vec (mapcat :pages-and-blocks page-exports'))
+                      :pvalue-uuids (set (mapcat :pvalue-uuids page-exports'))}]
     pages-export))
 
 (defn- build-graph-files
@@ -569,7 +572,7 @@
    and readability"
   [pages-and-blocks]
   (vec
-   (sort-by #(or (get-in % [:page :block/title]) (get-in % [:page :block/title]))
+   (sort-by #(or (get-in % [:page :block/title]) (str (get-in % [:page :build/journal])))
             pages-and-blocks)))
 
 (defn- add-ontology-for-include-namespaces
@@ -593,10 +596,11 @@
    * :include-timestamps? - When set timestamps are included on all blocks
    * :exclude-namespaces - A set of parent namespaces to exclude from properties and classes.
      This is useful for graphs seeded with an ontology e.g. schema.org as it eliminates noisy and needless
-     export+import"
+     export+import
+   * :exclude-built-in-pages? - When set built-in pages are excluded from export"
   [db options*]
   (let [options (merge options* {:property-value-uuids? true})
-        content-ref-uuids (get-graph-content-ref-uuids db)
+        content-ref-uuids (get-graph-content-ref-uuids db options)
         ontology-options (merge options {:include-uuid? true})
         ontology-export (build-graph-ontology-export db ontology-options)
         ontology-pvalue-uuids (set (concat (mapcat get-pvalue-uuids (vals (:properties ontology-export)))