mirror of
https://github.com/logseq/logseq.git
synced 2026-04-28 16:15:21 +00:00
Org-roam integration
Also add page aliases support
This commit is contained in:
@@ -14,14 +14,20 @@
|
||||
(vector? block)
|
||||
(= "Heading" (first block))))
|
||||
|
||||
(defn page-reference-block?
|
||||
(defn get-page-reference
|
||||
[block]
|
||||
(and
|
||||
(vector? block)
|
||||
(= "Link" (first block))
|
||||
(= "Search" (first (:url (second block))))
|
||||
(not (contains? #{\# \*} (first (second (:url (second block))))))
|
||||
))
|
||||
(when (and (vector? block) (= "Link" (first block)))
|
||||
(let [typ (first (:url (second block)))]
|
||||
(or
|
||||
(and
|
||||
(= typ "Search")
|
||||
(not (contains? #{\# \*} (first (second (:url (second block))))))
|
||||
(second (:url (second block))))
|
||||
|
||||
(and
|
||||
(= typ "Complex")
|
||||
(= (:protocol (second (:url (second block)))) "file")
|
||||
(:link (second (:url (second block)))))))))
|
||||
|
||||
(defn task-block?
|
||||
[block]
|
||||
@@ -76,7 +82,7 @@
|
||||
[tags]
|
||||
(mapv (fn [tag]
|
||||
{:db/id tag
|
||||
:tag/name tag})
|
||||
:tag/name (string/lower-case tag)})
|
||||
tags))
|
||||
|
||||
(defn with-refs
|
||||
@@ -84,9 +90,8 @@
|
||||
(let [ref-pages (atom [])]
|
||||
(walk/postwalk
|
||||
(fn [form]
|
||||
(when (page-reference-block? form)
|
||||
(let [page (second (:url (second form)))]
|
||||
(swap! ref-pages conj (string/capitalize page))))
|
||||
(when-let [page (get-page-reference form)]
|
||||
(swap! ref-pages conj (string/lower-case page)))
|
||||
form)
|
||||
(concat title children))
|
||||
(assoc heading :ref-pages (vec @ref-pages))))
|
||||
@@ -201,7 +206,7 @@
|
||||
{:heading/ref-pages
|
||||
(mapv
|
||||
(fn [page]
|
||||
(let [page-name (string/capitalize page)
|
||||
(let [page-name (string/lower-case page)
|
||||
page {:page/name page-name}]
|
||||
(swap! ref-pages-atom conj page)
|
||||
page))
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
[frontend.config :as config]
|
||||
[clojure.string :as string]
|
||||
[frontend.loader :as loader]
|
||||
[cljs-bean.core :as bean]))
|
||||
[cljs-bean.core :as bean]
|
||||
[medley.core :as medley]))
|
||||
|
||||
(defn default-config
|
||||
[format]
|
||||
@@ -24,14 +25,59 @@
|
||||
(when (loaded?)
|
||||
(.parseJson js/window.Mldoc content (or config default-config))))
|
||||
|
||||
;; E.g "Foo Bar \"Bar Baz\""
|
||||
(defn- sep-by-quote-or-space
|
||||
[s]
|
||||
(some->>
|
||||
(string/split s #"\"")
|
||||
(remove string/blank?)
|
||||
(map (fn [s]
|
||||
(if (or (= " " (first s)) (= " " (last s)))
|
||||
;; space separated tags
|
||||
(string/split (string/trim s) #" ")
|
||||
s)))
|
||||
flatten
|
||||
distinct
|
||||
(map string/lower-case)))
|
||||
|
||||
(defn collect-page-directives
|
||||
[ast]
|
||||
(if (seq ast)
|
||||
(let [directive? (fn [item] (= "directive" (string/lower-case (first item))))
|
||||
directives (->> (take-while directive? ast)
|
||||
(map (fn [[_ k v]]
|
||||
[(keyword (string/lower-case k))
|
||||
v]))
|
||||
(into {}))
|
||||
directives (if (seq directives)
|
||||
(let [directives (->
|
||||
(cond-> directives
|
||||
(:roam_alias directives)
|
||||
(assoc :alias (:roam_alias directives))
|
||||
(:roam_tags directives)
|
||||
(assoc :tags (:roam_tags directives))
|
||||
(:roam_key directives)
|
||||
(assoc :key (:roam_key directives)))
|
||||
(dissoc :roam_alias :roam_tags :roam_key))]
|
||||
(-> directives
|
||||
(update :alias sep-by-quote-or-space)
|
||||
(update :tags sep-by-quote-or-space)))
|
||||
directives)
|
||||
other-ast (drop-while directive? ast)]
|
||||
(if (seq directives)
|
||||
(cons ["Directives" directives] other-ast)
|
||||
ast))
|
||||
ast))
|
||||
|
||||
(defn ->edn
|
||||
[content config]
|
||||
(try
|
||||
(if (string/blank? content)
|
||||
{}
|
||||
(-> content
|
||||
(parse-json config)
|
||||
(util/json->clj)))
|
||||
{}
|
||||
(-> content
|
||||
(parse-json config)
|
||||
(util/json->clj)
|
||||
(collect-page-directives)))
|
||||
(catch js/Error _e
|
||||
[])))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user