mirror of
https://github.com/logseq/logseq.git
synced 2026-04-30 17:06:23 +00:00
Move common uses of page-ref to its own ns
By having a specific ns for page-ref utils, our code is more readable
and intention revealing. Also found that
text/{get-page-name,page-ref-un-brackets!} was getting called in
contexts that didn't make sense e.g. query layer was checking for
markdown and org page-refs
This commit is contained in:
committed by
Tienson Qin
parent
8be0deecd0
commit
e0b1f6b2de
@@ -14,6 +14,7 @@
|
||||
[logseq.db.rules :as rules]
|
||||
[frontend.template :as template]
|
||||
[logseq.graph-parser.text :as text]
|
||||
[logseq.graph-parser.util.page-ref :as page-ref]
|
||||
[frontend.util.text :as text-util]
|
||||
[frontend.util :as util]))
|
||||
|
||||
@@ -60,8 +61,8 @@
|
||||
(= "tomorrow" input)
|
||||
(db-utils/date->int (t/plus (t/today) (t/days 1)))
|
||||
|
||||
(text/page-ref? input)
|
||||
(let [input (-> (text/page-ref-un-brackets! input)
|
||||
(page-ref/page-ref? input)
|
||||
(let [input (-> (page-ref/get-page-name input)
|
||||
(string/replace ":" "")
|
||||
(string/capitalize))]
|
||||
(when (date/valid-journal-title? input)
|
||||
@@ -92,8 +93,8 @@
|
||||
(= "tomorrow" input)
|
||||
(tc/to-long (t/plus (t/today) (t/days 1)))
|
||||
|
||||
(text/page-ref? input)
|
||||
(let [input (-> (text/page-ref-un-brackets! input)
|
||||
(page-ref/page-ref? input)
|
||||
(let [input (-> (page-ref/get-page-name input)
|
||||
(string/replace ":" "")
|
||||
(string/capitalize))]
|
||||
(when (date/valid-journal-title? input)
|
||||
@@ -298,7 +299,7 @@
|
||||
(rest e))
|
||||
tags (map (comp string/lower-case name) tags)]
|
||||
(when (seq tags)
|
||||
(let [tags (set (map (comp text/page-ref-un-brackets! string/lower-case name) tags))]
|
||||
(let [tags (set (map (comp page-ref/get-page-name! string/lower-case name) tags))]
|
||||
{:query (list 'page-tags '?p tags)
|
||||
:rules [:page-tags]}))))
|
||||
|
||||
@@ -342,14 +343,14 @@
|
||||
|
||||
(defn- build-page
|
||||
[e]
|
||||
(let [page-name (text/page-ref-un-brackets! (str (first (rest e))))
|
||||
(let [page-name (page-ref/get-page-name! (str (first (rest e))))
|
||||
page-name (util/page-name-sanity-lc page-name)]
|
||||
{:query (list 'page '?b page-name)
|
||||
:rules [:page]}))
|
||||
|
||||
(defn- build-namespace
|
||||
[e]
|
||||
(let [page-name (text/page-ref-un-brackets! (str (first (rest e))))
|
||||
(let [page-name (page-ref/get-page-name! (str (first (rest e))))
|
||||
page (util/page-name-sanity-lc page-name)]
|
||||
(when-not (string/blank? page)
|
||||
{:query (list 'namespace '?p page)
|
||||
@@ -357,7 +358,7 @@
|
||||
|
||||
(defn- build-page-ref
|
||||
[e]
|
||||
(let [page-name (-> (text/page-ref-un-brackets! e)
|
||||
(let [page-name (-> (page-ref/get-page-name! e)
|
||||
(util/page-name-sanity-lc))]
|
||||
{:query (list 'page-ref '?b page-name)
|
||||
:rules [:page-ref]}))
|
||||
@@ -381,7 +382,7 @@ Some bindings in this fn:
|
||||
; {:post [(or (nil? %) (map? %))]}
|
||||
(let [fe (first e)
|
||||
fe (when fe (symbol (string/lower-case (name fe))))
|
||||
page-ref? (text/page-ref? e)]
|
||||
page-ref? (page-ref/page-ref? e)]
|
||||
(when (or (and page-ref?
|
||||
(not (contains? #{'page-property 'page-tags} (:current-filter env))))
|
||||
(contains? #{'between 'property 'todo 'task 'priority 'sort-by 'page} fe)
|
||||
@@ -442,20 +443,21 @@ Some bindings in this fn:
|
||||
|
||||
(defn- pre-transform
|
||||
[s]
|
||||
(some-> s
|
||||
(string/replace text/page-ref-re "\"[[$1]]\"")
|
||||
(string/replace text-util/between-re
|
||||
(fn [[_ x]]
|
||||
(->> (string/split x #" ")
|
||||
(remove string/blank?)
|
||||
(map (fn [x]
|
||||
(if (or (contains? #{"+" "-"} (first x))
|
||||
(and (util/safe-re-find #"\d" (first x))
|
||||
(some #(string/ends-with? x %) ["y" "m" "d" "h" "min"])))
|
||||
(keyword (name x))
|
||||
x)))
|
||||
(string/join " ")
|
||||
(util/format "(between %s)"))))))
|
||||
(let [quoted-page-ref (str "\"" page-ref/left-brackets "$1" page-ref/right-brackets "\"")]
|
||||
(some-> s
|
||||
(string/replace page-ref/page-ref-re quoted-page-ref)
|
||||
(string/replace text-util/between-re
|
||||
(fn [[_ x]]
|
||||
(->> (string/split x #" ")
|
||||
(remove string/blank?)
|
||||
(map (fn [x]
|
||||
(if (or (contains? #{"+" "-"} (first x))
|
||||
(and (util/safe-re-find #"\d" (first x))
|
||||
(some #(string/ends-with? x %) ["y" "m" "d" "h" "min"])))
|
||||
(keyword (name x))
|
||||
x)))
|
||||
(string/join " ")
|
||||
(util/format "(between %s)")))))))
|
||||
|
||||
(defn- add-bindings!
|
||||
[form q]
|
||||
@@ -482,7 +484,7 @@ Some bindings in this fn:
|
||||
or?
|
||||
(cond
|
||||
(->> (flatten form)
|
||||
(remove text/page-ref?)
|
||||
(remove (every-pred string? page-ref/page-ref?))
|
||||
(some string?)) ; block full-text search
|
||||
(concat [['?b :block/content '?content]] [q])
|
||||
|
||||
@@ -499,7 +501,7 @@ Some bindings in this fn:
|
||||
[s]
|
||||
(when (and (string? s)
|
||||
(not (string/blank? s)))
|
||||
(let [s (if (= \# (first s)) (util/format "[[%s]]" (subs s 1)) s)
|
||||
(let [s (if (= \# (first s)) (page-ref/->page-ref (subs s 1)) s)
|
||||
form (some-> s
|
||||
(pre-transform)
|
||||
(reader/read-string))
|
||||
|
||||
Reference in New Issue
Block a user