Browse Source

enhance: all journal pages have #Journal class

Also add some support for importer to do the same
Gabriel Horner 1 year ago
parent
commit
39b0e3e368

+ 2 - 1
deps/db/src/logseq/db/sqlite/build.cljs

@@ -465,7 +465,8 @@
                                                    :block/title page-name
                                                    :block/uuid
                                                    (common-uuid/gen-uuid :journal-page-uuid date-int)
-                                                   :block/type "journal"})))))
+                                                   :block/type "journal"
+                                                   :block/tags :logseq.class/Journal})))))
                            m))]
     ;; Order matters as some steps depend on previous step having prepared blocks or pages in a certain way
     (->> pages-and-blocks

+ 4 - 2
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -350,8 +350,10 @@
                                                {:block/created-at current-ms
                                                 :block/updated-at current-ms}))
                                            (if journal-day
-                                             {:block/type "journal"
-                                              :block/journal-day journal-day}
+                                             (cond-> {:block/type "journal"
+                                                      :block/journal-day journal-day}
+                                               db-based?
+                                               (assoc :block/tags [:logseq.class/Journal]))
                                              {}))]
                                  [page page-entity])
 

+ 13 - 8
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -83,7 +83,10 @@
   [block db tag-classes page-names-to-uuids all-idents]
   (if (seq (:block/tags block))
     (let [page-tags (->> (:block/tags block)
-                         (remove #(or (:block.temp/new-class %) (contains? tag-classes (:block/name %))))
+                         (remove #(or (:block.temp/new-class %)
+                                      (contains? tag-classes (:block/name %))
+                                      ;; Ignore new class tags from extract
+                                      (= % :logseq.class/Journal)))
                          (map #(vector :block/uuid (get-page-uuid page-names-to-uuids (:block/name %))))
                          set)]
       (cond-> block
@@ -190,15 +193,17 @@
                                                :in $ ?journal-day
                                                :where [?b :block/journal-day ?journal-day]]
                                              db date-int))
-          deadline-page (or existing-journal-page
+          deadline-page (->
+                         (or existing-journal-page
                             ;; FIXME: Register new pages so that two different refs to same new page
                             ;; don't create different uuids and thus an invalid page
-                            (let [page-m (sqlite-util/build-new-page
-                                          (date-time-util/int->journal-title date-int (common-config/get-date-formatter user-config)))]
-                              (assoc page-m
-                                     :block/uuid (common-uuid/gen-uuid :journal-page-uuid date-int)
-                                     :block/type "journal"
-                                     :block/journal-day date-int)))]
+                             (let [page-m (sqlite-util/build-new-page
+                                           (date-time-util/int->journal-title date-int (common-config/get-date-formatter user-config)))]
+                               (assoc page-m
+                                      :block/uuid (common-uuid/gen-uuid :journal-page-uuid date-int)
+                                      :block/type "journal"
+                                      :block/journal-day date-int)))
+                         (assoc :block/tags :logseq.class/Journal))]
       {:block
        (-> block
            (assoc :logseq.task/deadline [:block/uuid (:block/uuid deadline-page)])

+ 9 - 6
src/main/frontend/worker/handler/page/db_based/page.cljs

@@ -18,12 +18,15 @@
                                              whiteboard? "whiteboard"
                                              (:block/type page) (:block/type page)
                                              :else "page"))
-          page' (merge page
-                       (when tags {:block/tags (mapv (fn [tag]
-                                                       (if (uuid? tag)
-                                                         (d/entity @conn [:block/uuid tag])
-                                                         tag))
-                                                     tags)}))
+          page' (cond-> page
+                  (seq tags)
+                  (update :block/tags
+                          (fnil into [])
+                          (mapv (fn [tag]
+                                  (if (uuid? tag)
+                                    (d/entity @conn [:block/uuid tag])
+                                    tag))
+                                tags)))
           property-vals-tx-m
           ;; Builds property values for built-in properties like logseq.property.pdf/file
           (db-property-build/build-property-values-tx-m