fix: current page not triggering and translating to current page

For logseq/db-test#28
This commit is contained in:
Gabriel Horner
2024-08-21 11:22:40 -04:00
parent 2141b30598
commit e14465e72c
2 changed files with 20 additions and 15 deletions

View File

@@ -19,27 +19,29 @@
(date/today))]
(let [block-uuid (parse-uuid current-page)
page (if block-uuid
(:block/page (db-utils/entity [:block/uuid block-uuid]))
(db-utils/entity [:block/uuid block-uuid])
(ldb/get-page (conn/get-db) current-page))
current-page' (:block/title page)]
(page-ref/->page-ref current-page')))})
(when current-page' (page-ref/->page-ref current-page'))))})
(def template-re #"<%([^%].*?)%>")
;; TODO: programmable
;; context information, date, current page
(defn resolve-dynamic-template!
[content]
(string/replace content #"<%([^%].*?)%>"
(string/replace content template-re
(fn [[_ match]]
(let [match (string/trim match)]
(cond
(string/blank? match)
""
(get (variable-rules) (string/lower-case match))
(get (variable-rules) (string/lower-case match))
:else
(if-let [nld (date/nld-parse match)]
(let [;; NOTE: This following cannot handle timezones
(string/blank? match)
""
(get (variable-rules) (string/lower-case match))
(get (variable-rules) (string/lower-case match))
:else
(if-let [nld (date/nld-parse match)]
(let [;; NOTE: This following cannot handle timezones
;; date (tc/to-local-date-time nld)
date (doto (goog.date.DateTime.) (.setTime (.getTime nld)))]
(page-ref/->page-ref (date/journal-name date)))
match))))))
date (doto (goog.date.DateTime.) (.setTime (.getTime nld)))]
(page-ref/->page-ref (date/journal-name date)))
match))))))