Skip to content

Commit 08ab09a

Browse files
committed
fix: property issues
1 parent 7ad7e0b commit 08ab09a

4 files changed

Lines changed: 229 additions & 99 deletions

File tree

deps/publish/src/logseq/publish/worker.cljs

Lines changed: 84 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
[entity]
289289
(or (:block/title entity)
290290
(:block/name entity)
291+
(str (:logseq.property/value entity))
291292
"Untitled"))
292293

293294
(defn page-entity?
@@ -312,6 +313,18 @@
312313
(coll? value) (empty? value)
313314
:else false))
314315

316+
(defn format-datetime
317+
[value]
318+
(let [date (cond
319+
(instance? js/Date value) value
320+
(number? value) (js/Date. value)
321+
(string? value) (js/Date. value)
322+
:else nil)]
323+
(when date
324+
(-> (.toISOString date)
325+
(string/replace "T" " ")
326+
(string/replace "Z" "")))))
327+
315328
(defn nodes-join
316329
[nodes-list sep]
317330
(reduce (fn [acc nodes]
@@ -347,40 +360,80 @@
347360
[]
348361

349362
(string? value)
350-
(content->nodes value (:uuid->title ctx) (:graph-uuid ctx))
363+
(if (= prop-type :datetime)
364+
(if-let [formatted (format-datetime value)]
365+
[formatted]
366+
(content->nodes value (:uuid->title ctx) (:graph-uuid ctx)))
367+
(content->nodes value (:uuid->title ctx) (:graph-uuid ctx)))
351368

352369
(keyword? value)
353370
[(name value)]
354371

355372
(map? value)
356373
(if-let [eid (:db/id value)]
357374
(property-value->nodes eid prop-key ctx entities)
358-
[(pr-str value)])
375+
(if-let [content (db-property/property-value-content value)]
376+
(property-value->nodes content prop-key ctx entities)
377+
[(pr-str value)]))
359378

360-
(set? value)
361-
(nodes-join (map #(property-value->nodes % prop-key ctx entities) value) ", ")
362-
363-
(sequential? value)
379+
(or (set? value) (sequential? value))
364380
(nodes-join (map #(property-value->nodes % prop-key ctx entities) value) ", ")
365381

366382
(number? value)
367-
(if (and ref-type? (get entities value))
383+
(cond
384+
(= prop-type :datetime)
385+
(if-let [formatted (format-datetime value)]
386+
[formatted]
387+
[(str value)])
388+
389+
(and ref-type? (get entities value))
368390
(entity->link-node (get entities value) ctx)
391+
392+
:else
369393
[(str value)])
370394

371395
:else
372396
[(str value)])))
373397

374-
(defn entity-properties
398+
(defn built-in-tag?
375399
[entity]
400+
(when-let [ident (:db/ident entity)]
401+
(= "logseq.class" (namespace ident))))
402+
403+
(defn filter-tags
404+
[values entities]
405+
(let [values (if (sequential? values) values [values])]
406+
(->> values
407+
(remove (fn [value]
408+
(cond
409+
(keyword? value) (= "logseq.class" (namespace value))
410+
:else
411+
(let [entity (cond
412+
(map? value) value
413+
(number? value) (get entities value)
414+
:else nil)]
415+
(and entity (built-in-tag? entity))))))
416+
vec)))
417+
418+
(defn entity-properties
419+
[entity ctx entities]
376420
(let [props (db-property/properties entity)
377421
inline-props (:block/properties entity)
378422
props (if (map? inline-props)
379423
(merge props inline-props)
380-
props)]
381-
(into {}
382-
(remove (fn [[_ v]] (property-value-empty? v)))
383-
props)))
424+
props)
425+
props (->> props
426+
(remove (fn [[k _]]
427+
(true? (get (:property-hidden-by-ident ctx) k))))
428+
(map (fn [[k v]]
429+
(if (= k :block/tags)
430+
[k (filter-tags v entities)]
431+
[k v])))
432+
(remove (fn [[_ v]] (property-value-empty? v)))
433+
(remove (fn [[k v]]
434+
(and (= k :block/tags) (property-value-empty? v)))))
435+
props (into {} props)]
436+
props))
384437

385438
(defn render-properties
386439
[props ctx entities]
@@ -604,16 +657,16 @@
604657
(let [child-id (:db/id block)
605658
nested (render-block-tree children-by-parent child-id ctx)
606659
has-children? (boolean nested)
607-
properties (render-properties (entity-properties block)
660+
properties (render-properties (entity-properties block ctx (:entities ctx))
608661
ctx
609662
(:entities ctx))]
610663
[:li.block
611664
[:div.block-content
665+
(block-content-nodes block ctx)
612666
(when has-children?
613667
[:button.block-toggle
614668
{:type "button" :aria-expanded "true"}
615-
""])
616-
(block-content-nodes block ctx)]
669+
""])]
617670
(when properties
618671
[:div.block-properties properties])
619672
(when nested
@@ -668,12 +721,8 @@
668721
name->uuid (reduce (fn [acc [_e entity]]
669722
(if-let [uuid-value (:block/uuid entity)]
670723
(let [uuid-str (str uuid-value)
671-
name (:block/name entity)
672724
title (:block/title entity)]
673-
(cond-> acc
674-
name (assoc name uuid-str)
675-
title (assoc title uuid-str)
676-
title (assoc (common-util/page-name-sanity-lc title) uuid-str)))
725+
(assoc acc title uuid-str))
677726
acc))
678727
{}
679728
entities)
@@ -689,10 +738,17 @@
689738
acc))
690739
{}
691740
entities)
741+
property-hidden-by-ident (reduce (fn [acc [_e entity]]
742+
(if-let [ident (:db/ident entity)]
743+
(assoc acc ident (true? (:logseq.property/hide? entity)))
744+
acc))
745+
{}
746+
entities)
692747
children-by-parent (->> entities
693748
(reduce (fn [acc [e entity]]
694749
(if (and (= (:block/page entity) page-eid)
695-
(not= e page-eid))
750+
(not= e page-eid)
751+
(not (:logseq.property/created-from-property entity)))
696752
(let [parent (or (:block/parent entity) page-eid)]
697753
(update acc parent (fnil conj []) entity))
698754
acc))
@@ -705,8 +761,9 @@
705761
:graph-uuid graph-uuid
706762
:property-title-by-ident property-title-by-ident
707763
:property-type-by-ident property-type-by-ident
764+
:property-hidden-by-ident property-hidden-by-ident
708765
:entities entities}
709-
page-properties (render-properties (entity-properties page-entity)
766+
page-properties (render-properties (entity-properties page-entity ctx entities)
710767
ctx
711768
entities)
712769
blocks (render-block-tree children-by-parent page-eid ctx)
@@ -744,7 +801,7 @@
744801
".property-value{margin:0;color:#2e2a23;}"
745802
".block-properties{margin:6px 0 0 22px;}"
746803
".block-properties .properties{grid-template-columns:120px 1fr;font-size:13px;}"
747-
".block-toggle{border:none;background:transparent;cursor:pointer;font-size:14px;line-height:1;margin-top:3px;color:#6b7280;}"
804+
".block-toggle{border:none;background:transparent;cursor:pointer;font-size:14px;line-height:1;margin-top:3px;margin-left:auto;color:#6b7280;}"
748805
".block.is-collapsed >.block-content >.block-toggle {transform: rotate(-90deg);}"
749806
".block-toggle:focus{outline:2px solid #c7b38f;outline-offset:2px;border-radius:4px;}"
750807
".block-children{margin-left:16px;}"
@@ -797,8 +854,10 @@
797854
payload-entities)
798855
page-title (when page-eid
799856
(entity->title (get payload-entities page-eid)))
800-
refs (when (and page-eid page-title)
801-
(page-refs-from-payload payload page-eid page_uuid page-title graph))]
857+
refs (or (:refs payload)
858+
(get payload "refs")
859+
(when (and page-eid page-title)
860+
(page-refs-from-payload payload page-eid page_uuid page-title graph)))]
802861
(cond
803862
(not (valid-meta? meta))
804863
(bad-request "missing publish metadata")
Lines changed: 25 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,13 @@
11
(ns frontend.handler.publish
22
"Prepare publish payloads for pages."
3-
(:require [datascript.core :as d]
4-
[frontend.config :as config]
3+
(:require [frontend.config :as config]
54
[frontend.db :as db]
65
[frontend.handler.notification :as notification]
76
[frontend.state :as state]
87
[frontend.util :as util]
98
[logseq.db :as ldb]
10-
[logseq.db.common.entity-util :as entity-util]
11-
[logseq.db.frontend.property :as db-property]
12-
[logseq.db.frontend.schema :as db-schema]
139
[promesa.core :as p]))
1410

15-
(defn- datom->vec
16-
[datom]
17-
[(:e datom) (:a datom) (:v datom) (:tx datom) (:added datom)])
18-
19-
(defn- collect-page-eids
20-
[db page-entity]
21-
(let [page-id (:db/id page-entity)
22-
blocks (ldb/get-page-blocks db page-id)
23-
block-eids (map :db/id blocks)
24-
ref-eids (->> blocks (mapcat :block/refs) (keep :db/id))
25-
tag-eids (->> blocks (mapcat :block/tags) (keep :db/id))
26-
page-eids (->> blocks (map :block/page) (keep :db/id))
27-
property-eids (->> (cons page-entity blocks)
28-
(map db-property/properties)
29-
(mapcat (fn [props]
30-
(concat
31-
(keep (fn [k]
32-
(when (keyword? k)
33-
(:db/id (d/entity db k))))
34-
(keys props))
35-
(mapcat (fn [v]
36-
(cond
37-
(nil? v) []
38-
(set? v) (keep :db/id v)
39-
(sequential? v) (keep :db/id v)
40-
:else (keep :db/id [v])))
41-
(vals props)))))
42-
(remove nil?))]
43-
{:blocks blocks
44-
:eids (->> (concat [page-id] block-eids ref-eids tag-eids page-eids property-eids)
45-
(remove nil?)
46-
distinct)}))
47-
48-
(defn build-page-publish-datoms
49-
"Builds a datom snapshot for a single page.
50-
51-
References/backlinks are intentionally ignored at this stage.
52-
"
53-
[db page-entity]
54-
(let [{:keys [blocks eids]} (collect-page-eids db page-entity)
55-
datoms (mapcat (fn [eid]
56-
(map datom->vec (d/datoms db :eavt eid)))
57-
eids)]
58-
{:page (entity-util/entity->map page-entity)
59-
:page-uuid (:block/uuid page-entity)
60-
:block-count (count blocks)
61-
:schema-version (db-schema/schema-version->string db-schema/version)
62-
:datoms (vec datoms)}))
63-
6411
(defn- <sha256-hex
6512
[text]
6613
(p/let [encoder (js/TextEncoder.)
@@ -83,7 +30,8 @@
8330
token (assoc "authorization" (str "Bearer " token)))]
8431
(p/let [body (ldb/write-transit-str payload)
8532
content-hash (<sha256-hex body)
86-
graph-uuid (some-> (ldb/get-graph-rtc-uuid (db/get-db)) str)
33+
graph-uuid (or (:graph-uuid payload)
34+
(some-> (ldb/get-graph-rtc-uuid (db/get-db)) str))
8735
_ (when-not graph-uuid
8836
(throw (ex-info "Missing graph UUID" {:repo (state/get-current-repo)})))
8937
publish-meta {:graph graph-uuid
@@ -114,24 +62,27 @@
11462
(let [repo (state/get-current-repo)]
11563
(if-let [db* (and repo (db/get-db repo))]
11664
(if (and page (:db/id page))
117-
(let [payload (build-page-publish-datoms db* page)]
118-
(-> (<post-publish! payload)
119-
(p/then (fn [_resp]
120-
(let [graph-uuid (some-> (ldb/get-graph-rtc-uuid db*) str)
121-
page-uuid (some-> (:block/uuid page) str)
122-
url (when (and graph-uuid page-uuid)
123-
(str config/PUBLISH-API-BASE "/p/" graph-uuid "/" page-uuid))]
124-
(when url
125-
(notification/show!
126-
[:div.inline
127-
[:span "Published to: "]
128-
[:a {:target "_blank"
129-
:href url}
130-
url]]
131-
:success
132-
false)))))
133-
(p/catch (fn [error]
134-
(js/console.error error)
135-
(notification/show! "Publish failed." :error)))))
65+
(p/let [payload (state/<invoke-db-worker :thread-api/build-publish-page-payload repo (:db/id page))]
66+
(if payload
67+
(-> (<post-publish! payload)
68+
(p/then (fn [_resp]
69+
(let [graph-uuid (or (:graph-uuid payload)
70+
(some-> (ldb/get-graph-rtc-uuid db*) str))
71+
page-uuid (str (:block/uuid page))
72+
url (when (and graph-uuid page-uuid)
73+
(str config/PUBLISH-API-BASE "/p/" graph-uuid "/" page-uuid))]
74+
(when url
75+
(notification/show!
76+
[:div.inline
77+
[:span "Published to: "]
78+
[:a {:target "_blank"
79+
:href url}
80+
url]]
81+
:success
82+
false)))))
83+
(p/catch (fn [error]
84+
(js/console.error error)
85+
(notification/show! "Publish failed." :error))))
86+
(notification/show! "Publish failed: invalid page." :error)))
13687
(notification/show! "Publish failed: invalid page." :error))
13788
(notification/show! "Publish failed: missing database." :error))))

src/main/frontend/worker/db_worker.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
[frontend.worker.export :as worker-export]
2424
[frontend.worker.handler.page :as worker-page]
2525
[frontend.worker.pipeline :as worker-pipeline]
26+
[frontend.worker.publish]
2627
[frontend.worker.rtc.asset-db-listener]
2728
[frontend.worker.rtc.client-op :as client-op]
2829
[frontend.worker.rtc.core :as rtc.core]

0 commit comments

Comments
 (0)