Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
[lambdaisland.glogi :as log]
[frontend.context.i18n :as i18n]
[frontend.template :as template]
[shadow.loader :as loader]))
[shadow.loader :as loader]
[frontend.search :as search]))

;; TODO: remove rum/with-context because it'll make reactive queries not working

Expand Down Expand Up @@ -889,13 +890,50 @@
(get name))
(get (state/get-macros) name)
(get (state/get-macros) (keyword name)))
macro-content (if (and (seq arguments) macro-content)
macro-content (cond
(= (str name) "img")
(case (count arguments)
1
(util/format "[:img {:src \"%s\"}]" (first arguments))
4
(if (and (util/safe-parse-int (nth arguments 1))
(util/safe-parse-int (nth arguments 2)))
(util/format "[:img.%s {:src \"%s\" :style {:width %s :height %s}}]"
(nth arguments 3)
(first arguments)
(util/safe-parse-int (nth arguments 1))
(util/safe-parse-int (nth arguments 2))))
3
(if (and (util/safe-parse-int (nth arguments 1))
(util/safe-parse-int (nth arguments 2)))
(util/format "[:img {:src \"%s\" :style {:width %s :height %s}}]"
(first arguments)
(util/safe-parse-int (nth arguments 1))
(util/safe-parse-int (nth arguments 2))))

2
(cond
(and (util/safe-parse-int (nth arguments 1)))
(util/format "[:img {:src \"%s\" :style {:width %s}}]"
(first arguments)
(util/safe-parse-int (nth arguments 1)))
(contains? #{"left" "right" "center"} (string/lower-case (nth arguments 1)))
(util/format "[:img.%s {:src \"%s\"}]"
(string/lower-case (nth arguments 1))
(first arguments))
:else
macro-content)

macro-content)

(and (seq arguments) macro-content)
(block/macro-subs macro-content arguments)

:else
macro-content)
macro-content (when macro-content
(template/resolve-dynamic-template! macro-content))]
(render-macro config name arguments macro-content format))

(when-let [macro-txt (macro->text name arguments)]
(let [macro-txt (when macro-txt
(template/resolve-dynamic-template! macro-txt))
Expand Down Expand Up @@ -1747,7 +1785,15 @@
[state]
(let [[config query] (:rum/args state)
query-atom (if (:dsl-query? config)
(query-dsl/query (state/get-current-repo) (:query query))
(let [result (query-dsl/query (state/get-current-repo) (:query query))]
(if (string? result) ; full-text search
(atom
(if (string/blank? result)
[]
(let [blocks (search/block-search result 50)]
(when (seq blocks)
(db/pull-many (state/get-current-repo) '[*] (map (fn [b] [:block/uuid (uuid (:block/uuid b))]) blocks))))))
result))
(db/custom-query query))]
(assoc state :query-atom query-atom)))

Expand Down Expand Up @@ -1983,7 +2029,7 @@

["Custom" "warning" options result content]
(admonition config "warning" options result)

["Custom" "pinned" options result content]
(admonition config "pinned" options result)

Expand Down Expand Up @@ -2041,6 +2087,7 @@
(fn [acc block]
(let [block (dissoc block :block/meta)
level (:block/level block)
config (assoc config :block/uuid (:block/uuid block))
block-cp (if build-block-fn
(build-block-fn config block)
(rum/with-key
Expand Down
1 change: 0 additions & 1 deletion src/main/frontend/components/journal.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
(let [;; Don't edit the journal title
page (string/lower-case title)
repo (state/sub :git/current-repo)
encoded-page-name (util/encode-str page)
today? (= (string/lower-case title)
(string/lower-case (date/journal-name)))
intro? (and (not (state/logged?))
Expand Down
36 changes: 17 additions & 19 deletions src/main/frontend/components/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@
[state {:keys [repo] :as option}]
(let [current-repo (state/sub :git/current-repo)
repo (or repo current-repo)
encoded-page-name (or (get-page-name state)
(state/get-current-page))
path-page-name (util/url-decode encoded-page-name)
path-page-name (or (get-page-name state)
(state/get-current-page))
page-name (string/lower-case path-page-name)
marker-page? (util/marker? page-name)
priority-page? (contains? #{"a" "b" "c"} page-name)
Expand Down Expand Up @@ -437,7 +436,7 @@
(block/block-parents config repo block-id format)]))

;; blocks
(page-blocks-cp repo page file-path page-name page-original-name encoded-page-name sidebar? journal? block? block-id format)]]
(page-blocks-cp repo page file-path page-name page-original-name page-name sidebar? journal? block? block-id format)]]

(when-not block?
(today-queries repo today? sidebar?))
Expand Down Expand Up @@ -516,21 +515,20 @@
[:th (t :file/last-modified-at)]]]
[:tbody
(for [page pages]
(let [encoded-page (util/encode-str page)]
[:tr {:key encoded-page}
[:td [:a {:on-click (fn [e]
(let [repo (state/get-current-repo)
page (db/pull repo '[*] [:page/name (string/lower-case page)])]
(when (gobj/get e "shiftKey")
(state/sidebar-add-block!
repo
(:db/id page)
:page
{:page page}))))
:href (rfe/href :page {:name encoded-page})}
page]]
[:td [:span.text-gray-500.text-sm
(t :file/no-data)]]]))]]))])))
[:tr {:key page}
[:td [:a {:on-click (fn [e]
(let [repo (state/get-current-repo)
page (db/pull repo '[*] [:page/name (string/lower-case page)])]
(when (gobj/get e "shiftKey")
(state/sidebar-add-block!
repo
(:db/id page)
:page
{:page page}))))
:href (rfe/href :page {:name page})}
page]]
[:td [:span.text-gray-500.text-sm
(t :file/no-data)]]])]]))])))

(rum/defcs new < rum/reactive
(rum/local "" ::title)
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/right_sidebar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@

(date/journal-name))]
(if page
(util/url-decode (string/lower-case page)))))
(string/lower-case page))))

(defn get-current-page
[]
Expand Down
3 changes: 2 additions & 1 deletion src/main/frontend/db/model.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@
(->> (string/split-lines content)
(take-while (fn [line]
(or (string/blank? line)
(string/starts-with? line "#+"))))
(string/starts-with? line "#+")
(re-find #"^:.+?:" line))))
(string/join "\n"))

:markdown
Expand Down
87 changes: 47 additions & 40 deletions src/main/frontend/db/query_dsl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@

(defn query-wrapper
[where blocks?]
(let [q (if blocks? ; FIXME: it doesn't need to be either blocks or pages
'[:find (pull ?b [*])
:where]
'[:find (pull ?p [*])
:where])
result (if (coll? (first where))
(apply conj q where)
(conj q where))]
(prn "Datascript query: " result)
result))
(when where
(let [q (if blocks? ; FIXME: it doesn't need to be either blocks or pages
'[:find (pull ?b [*])
:where]
'[:find (pull ?p [*])
:where])
result (if (coll? (first where))
(apply conj q where)
(conj q where))]
(prn "Datascript query: " result)
result)))

;; (between -7d +7d)
(defn- ->journal-day-int [input]
Expand Down Expand Up @@ -151,7 +152,7 @@
(contains? #{'and 'or 'not} fe)
(let [clauses (->> (map (fn [form]
(build-query repo form (assoc env :current-filter fe) (inc level)))
(rest e))
(rest e))
remove-nil?
(distinct))]
(when (seq clauses)
Expand Down Expand Up @@ -221,7 +222,7 @@
(text/page-ref-un-brackets!))
sym (if (= current-filter 'or)
'?v
(uniq-symbol counter "?v"))]
(uniq-symbol counter "?v"))]
[['?b :block/properties '?prop]
[(list 'get '?prop (name (nth e 1))) sym]
(list
Expand Down Expand Up @@ -354,39 +355,45 @@
(try
(let [form (some-> s
(pre-transform)
(reader/read-string))
sort-by (atom nil)
blocks? (atom nil)
result (when form (build-query repo form {:sort-by sort-by
:blocks? blocks?
:counter counter}))
result (when (seq result)
(let [key (if (coll? (first result))
(keyword (ffirst result))
(keyword (first result)))
result (case key
:and
(rest result)

result)]
(add-bindings! result)))]
{:query result
:sort-by @sort-by
:blocks? (boolean @blocks?)})
(reader/read-string))]
(if (symbol? form)
(str form)
(let [sort-by (atom nil)
blocks? (atom nil)
result (when form (build-query repo form {:sort-by sort-by
:blocks? blocks?
:counter counter}))]
(if (string? result)
result
(let [result (when (seq result)
(let [key (if (coll? (first result))
(keyword (ffirst result))
(keyword (first result)))
result (case key
:and
(rest result)

result)]
(add-bindings! result)))]
{:query result
:sort-by @sort-by
:blocks? (boolean @blocks?)})))))
(catch js/Error e
(log/error :query-dsl/parse-error e))))))

(defn query
[repo query-string]
(when (string? query-string)
(let [query-string (template/resolve-dynamic-template! query-string)
{:keys [query sort-by blocks?]} (parse repo query-string)]
(when query
(let [query (query-wrapper query blocks?)]
(react/react-query repo
{:query query}
(if sort-by
{:transform-fn sort-by})))))))
(let [query-string (template/resolve-dynamic-template! query-string)]
(when-not (string/blank? query-string)
(let [{:keys [query sort-by blocks?] :as result} (parse repo query-string)]
(if (string? result)
result
(when-let [query (query-wrapper query blocks?)]
(react/react-query repo
{:query query}
(if sort-by
{:transform-fn sort-by})))))))))

(defn custom-query
[repo query-m query-opts]
Expand All @@ -395,7 +402,7 @@
query-string (template/resolve-dynamic-template! query-string)
{:keys [query sort-by blocks?]} (parse repo query-string)]
(when query
(let [query (query-wrapper query blocks?)]
(when-let [query (query-wrapper query blocks?)]
(react/react-query repo
(merge
query-m
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/db/query_react.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@
k [:custom query']]
(apply react/q repo k query-opts query inputs))
(catch js/Error e
(println "Custom query failed: ")
(println "Custom query failed: " {:query query'})
(js/console.dir e))))
2 changes: 1 addition & 1 deletion src/main/frontend/db/react.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@

(date/journal-name))]
(when page
(let [page-name (util/url-decode (string/lower-case page))]
(let [page-name (string/lower-case page)]
(db-utils/entity [:page/name page-name])))))

(defn get-current-priority
Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/format.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
(protocol/loaded? record)))

(def marker-pattern
#"^(NOW|LATER|TODO|DOING|DONE|WAIT|WAITING|CANCELED|CANCELLED|STARTED|IN-PROGRESS)?\s?")
#"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS)?\s?")

(def bare-marker-pattern
#"^(NOW|LATER|TODO|DOING|DONE|WAIT|WAITING|CANCELED|CANCELLED|STARTED|IN-PROGRESS){1}\s+")
#"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS){1}\s+")
7 changes: 5 additions & 2 deletions src/main/frontend/format/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@
(swap! ref-pages conj tag)))
form)
(concat title body))
(let [ref-pages (remove string/blank? @ref-pages)]
(assoc block :ref-pages (vec ref-pages)))))
(let [ref-pages (remove string/blank? @ref-pages)
children-pages (->> (mapcat (fn [p] (if (string/includes? p "/") (string/split p #"/"))) ref-pages)
(remove string/blank?))
ref-pages (distinct (concat ref-pages children-pages))]
(assoc block :ref-pages ref-pages))))

(defn with-block-refs
[{:keys [title body] :as block}]
Expand Down
12 changes: 8 additions & 4 deletions src/main/frontend/format/mldoc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,20 @@
(if (seq ast)
(let [original-ast ast
ast (map first ast) ; without position meta
directive? (fn [item] (= "directive" (string/lower-case (first item))))
properties (->> (take-while directive? ast)
directive?
(fn [[item _]] (= "directive" (string/lower-case (first item))))
grouped-ast (group-by directive? original-ast)
[directive-ast other-ast]
[(get grouped-ast true) (get grouped-ast false)]
properties (->> (map first directive-ast)
(map (fn [[_ k v]]
(let [k (keyword (string/lower-case k))
comma? (contains? #{:tags :alias :roam_tags} k)
v (if (contains? #{:title :description :roam_tags} k)
v
(text/split-page-refs-without-brackets v comma?))]
[k v])))
(reverse)
(into {}))
macro-properties (filter (fn [x] (= :macro (first x))) properties)
macros (if (seq macro-properties)
Expand Down Expand Up @@ -134,8 +139,7 @@
(update :roam_alias ->vec)
(update :roam_tags (constantly roam-tags))
(update :filetags (constantly filetags)))
properties (medley/filter-kv (fn [k v] (not (empty? v))) properties)
other-ast (drop-while (fn [[item _pos]] (directive? item)) original-ast)]
properties (medley/filter-kv (fn [k v] (not (empty? v))) properties)]
(if (seq properties)
(cons [["Properties" properties] nil] other-ast)
original-ast))
Expand Down
4 changes: 3 additions & 1 deletion src/main/frontend/handler/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
file (db/entity (:db/id (:page/file page)))
file-path (:file/path file)
file-content (db/get-file file-path)
after-content (subs file-content (inc (count properties-content)))
after-content (if (empty? properties-content)
file-content
(subs file-content (inc (count properties-content))))
new-properties-content (db/add-properties! page-format properties-content properties)
full-content (str new-properties-content "\n\n" (string/trim after-content))]
(file-handler/alter-file (state/get-current-repo)
Expand Down
Loading