mirror of https://github.com/logseq/logseq
Extract definition tags too
parent
ef06150414
commit
c4590acffe
|
@ -52,14 +52,14 @@
|
|||
[repo page file-path page-name page-original-name encoded-page-name sidebar? journal? block? block-id format]
|
||||
(let [raw-page-blocks (get-blocks repo page-name page-original-name block? block-id)
|
||||
page-blocks (db/with-dummy-block raw-page-blocks format
|
||||
(if (empty? raw-page-blocks)
|
||||
(let [content (db/get-file repo file-path)]
|
||||
{:block/page {:db/id (:db/id page)}
|
||||
:block/file {:db/id (:db/id (:page/file page))}
|
||||
:block/meta
|
||||
(let [file-id (:db/id (:page/file page))]
|
||||
{:start-pos (utf8/length (utf8/encode content))
|
||||
:end-pos nil})}))
|
||||
(if (empty? raw-page-blocks)
|
||||
(let [content (db/get-file repo file-path)]
|
||||
{:block/page {:db/id (:db/id page)}
|
||||
:block/file {:db/id (:db/id (:page/file page))}
|
||||
:block/meta
|
||||
(let [file-id (:db/id (:page/file page))]
|
||||
{:start-pos (utf8/length (utf8/encode content))
|
||||
:end-pos nil})}))
|
||||
journal?)
|
||||
start-level (or (:block/level (first page-blocks)) 1 )
|
||||
hiccup-config {:id encoded-page-name
|
||||
|
@ -220,6 +220,7 @@
|
|||
repo (or repo current-repo)
|
||||
encoded-page-name (get-page-name state)
|
||||
page-name (string/lower-case (util/url-decode encoded-page-name))
|
||||
path-page-name page-name
|
||||
marker-page? (util/marker? page-name)
|
||||
priority-page? (contains? #{"a" "b" "c"} page-name)
|
||||
format (db/get-page-format page-name)
|
||||
|
@ -309,11 +310,16 @@
|
|||
:page
|
||||
{:page page}))))}
|
||||
[:h1.title {:style {:margin-left -2}}
|
||||
(if (and (string/includes? page-original-name "[[")
|
||||
(string/includes? page-original-name "]]"))
|
||||
(let [ast (mldoc/->edn page-original-name (mldoc/default-config format))]
|
||||
(hiccup/block-cp {} (ffirst ast)))
|
||||
page-original-name)]])
|
||||
(if page-original-name
|
||||
(if (and (string/includes? page-original-name "[[")
|
||||
(string/includes? page-original-name "]]"))
|
||||
(when page-original-name
|
||||
(let [ast (mldoc/->edn page-original-name (mldoc/default-config format))]
|
||||
(hiccup/block-cp {} (ffirst ast))))
|
||||
page-original-name)
|
||||
(or
|
||||
page-name
|
||||
path-page-name))]])
|
||||
[:div
|
||||
[:div.content
|
||||
(when (and file-path (not sidebar?) (not block?))
|
||||
|
|
|
@ -227,7 +227,10 @@
|
|||
(pull-many (state/get-current-repo) selector eids))
|
||||
([repo selector eids]
|
||||
(when-let [conn (get-conn repo)]
|
||||
(d/pull-many conn selector eids))))
|
||||
(try
|
||||
(d/pull-many conn selector eids)
|
||||
(catch js/Error e
|
||||
(js/console.error e))))))
|
||||
|
||||
(defn get-handler-keys
|
||||
[{:keys [key data]}]
|
||||
|
@ -1119,6 +1122,7 @@
|
|||
_ (transact! repo-url block-refs)
|
||||
pages (pages-fn blocks ast)
|
||||
ref-pages (atom #{})
|
||||
ref-tags (atom #{})
|
||||
blocks (doall
|
||||
(mapcat
|
||||
(fn [[page blocks]]
|
||||
|
@ -1139,73 +1143,82 @@
|
|||
block-ref-pages)))))
|
||||
blocks)))
|
||||
(remove nil? pages)))
|
||||
pages (map
|
||||
(fn [page]
|
||||
(let [page-file? (= page (string/lower-case file))
|
||||
other-alias (and (:alias directives)
|
||||
(seq (remove #(= page %)
|
||||
(:alias directives))))
|
||||
other-alias (distinct
|
||||
(remove nil? other-alias))
|
||||
journal-date-long (if journal?
|
||||
(date/journal-title->long (string/capitalize page)))
|
||||
page-list (when-let [list-content (:list directives)]
|
||||
(extract-page-list list-content))]
|
||||
(cond->
|
||||
(util/remove-nils
|
||||
{:page/name (string/lower-case page)
|
||||
:page/original-name page
|
||||
:page/file [:file/path file]
|
||||
:page/journal? journal?
|
||||
:page/journal-day (if journal?
|
||||
(date/journal-title->int (string/capitalize page))
|
||||
0)
|
||||
:page/created-at journal-date-long
|
||||
:page/last-modified-at journal-date-long})
|
||||
(seq directives)
|
||||
(assoc :page/directives directives)
|
||||
pages (doall
|
||||
(map
|
||||
(fn [page]
|
||||
(let [page-file? (= page (string/lower-case file))
|
||||
other-alias (and (:alias directives)
|
||||
(seq (remove #(= page %)
|
||||
(:alias directives))))
|
||||
other-alias (distinct
|
||||
(remove nil? other-alias))
|
||||
journal-date-long (if journal?
|
||||
(date/journal-title->long (string/capitalize page)))
|
||||
page-list (when-let [list-content (:list directives)]
|
||||
(extract-page-list list-content))]
|
||||
(cond->
|
||||
(util/remove-nils
|
||||
{:page/name (string/lower-case page)
|
||||
:page/original-name page
|
||||
:page/file [:file/path file]
|
||||
:page/journal? journal?
|
||||
:page/journal-day (if journal?
|
||||
(date/journal-title->int (string/capitalize page))
|
||||
0)
|
||||
:page/created-at journal-date-long
|
||||
:page/last-modified-at journal-date-long})
|
||||
(seq directives)
|
||||
(assoc :page/directives directives)
|
||||
|
||||
other-alias
|
||||
(assoc :page/alias
|
||||
(map
|
||||
(fn [alias]
|
||||
(let [alias (string/lower-case alias)
|
||||
aliases (->>
|
||||
(distinct
|
||||
(conj
|
||||
(remove #{alias} other-alias)
|
||||
page))
|
||||
(remove nil?))
|
||||
aliases (if (seq aliases)
|
||||
(map
|
||||
(fn [alias]
|
||||
{:page/name alias})
|
||||
aliases))]
|
||||
(if (seq aliases)
|
||||
{:page/name alias
|
||||
:page/alias aliases}
|
||||
{:page/name alias})))
|
||||
other-alias))
|
||||
other-alias
|
||||
(assoc :page/alias
|
||||
(map
|
||||
(fn [alias]
|
||||
(let [alias (string/lower-case alias)
|
||||
aliases (->>
|
||||
(distinct
|
||||
(conj
|
||||
(remove #{alias} other-alias)
|
||||
page))
|
||||
(remove nil?))
|
||||
aliases (if (seq aliases)
|
||||
(map
|
||||
(fn [alias]
|
||||
{:page/name alias})
|
||||
aliases))]
|
||||
(if (seq aliases)
|
||||
{:page/name alias
|
||||
:page/alias aliases}
|
||||
{:page/name alias})))
|
||||
other-alias))
|
||||
|
||||
(or (:tags directives) (:roam_tags directives))
|
||||
(assoc :page/tags (let [tags (:tags directives)
|
||||
roam-tags (:roam_tags directives)
|
||||
tags (if (string? tags)
|
||||
(string/split tags #",")
|
||||
tags)
|
||||
tags (->> (concat tags roam-tags)
|
||||
(remove nil?)
|
||||
(distinct))]
|
||||
(util/->tags tags))))))
|
||||
(->> (map first pages)
|
||||
(remove nil?)))
|
||||
(or (:tags directives) (:roam_tags directives))
|
||||
(assoc :page/tags (let [tags (:tags directives)
|
||||
roam-tags (:roam_tags directives)
|
||||
tags (if (string? tags)
|
||||
(string/split tags #",")
|
||||
tags)
|
||||
tags (->> (concat tags roam-tags)
|
||||
(remove nil?)
|
||||
(distinct))
|
||||
tags (util/->tags tags)]
|
||||
(swap! ref-tags set/union (set (map :tag/name tags)))
|
||||
tags)))))
|
||||
(->> (map first pages)
|
||||
(remove nil?))))
|
||||
pages (concat
|
||||
pages
|
||||
(map
|
||||
(fn [page]
|
||||
{:page/original-name page
|
||||
:page/name page})
|
||||
@ref-tags)
|
||||
(map
|
||||
(fn [page]
|
||||
{:page/original-name page
|
||||
:page/name (string/lower-case page)})
|
||||
@ref-pages))]
|
||||
(prn {:pages pages})
|
||||
(vec
|
||||
(->> (concat
|
||||
pages
|
||||
|
|
|
@ -48,6 +48,8 @@
|
|||
:db/cardinality :db.cardinality/many}
|
||||
:page/tags {:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/many}
|
||||
:page/definitions {:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/many}
|
||||
:page/created-at {}
|
||||
:page/last-modified-at {}
|
||||
:page/contributors {}
|
||||
|
@ -94,4 +96,11 @@
|
|||
:db/unique :db.unique/identity}
|
||||
|
||||
;; For pages
|
||||
:tag/name {:db/unique :db.unique/identity}})
|
||||
:tag/name {:db/unique :db.unique/identity}
|
||||
|
||||
;; Definitions, useful for tags and future anki cards
|
||||
:definition/block {:db/valueType :db.type/ref}
|
||||
;; Why not make :definition/key unique?
|
||||
;; Multiple definitions with the same key in either one page or multiple pages
|
||||
:definition/key {}
|
||||
:definition/value {}})
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
[clojure.string :as string]
|
||||
[frontend.loader :as loader]
|
||||
[cljs-bean.core :as bean]
|
||||
[medley.core :as medley]))
|
||||
[medley.core :as medley]
|
||||
[cljs.core.match :refer-macros [match]]))
|
||||
|
||||
(defn default-config
|
||||
[format]
|
||||
|
@ -44,6 +45,39 @@
|
|||
(map string/lower-case)
|
||||
(map string/trim)))))
|
||||
|
||||
;; Org-roam
|
||||
(defn get-tags-from-definition
|
||||
[ast]
|
||||
(loop [ast ast]
|
||||
(if (seq ast)
|
||||
(match (first ast)
|
||||
["List" l]
|
||||
(when-let [name (:name (first l))]
|
||||
(let [name (and (vector? name)
|
||||
(last (first name)))]
|
||||
(when (and (string? name)
|
||||
(= (string/lower-case name) "tags"))
|
||||
(->>
|
||||
(last (first (:content (first l))))
|
||||
(map second)
|
||||
(filter (and map? :url))
|
||||
(map (fn [x]
|
||||
(let [label (last (first (:label x)))
|
||||
search (and (= (first (:url x)) "Search")
|
||||
(last (:url x)))
|
||||
tag (if-not (string/blank? label)
|
||||
label
|
||||
search)]
|
||||
(when tag (string/lower-case tag)))))
|
||||
(remove nil?)))))
|
||||
|
||||
["Heading" _h]
|
||||
nil
|
||||
|
||||
:else
|
||||
(recur (rest ast)))
|
||||
nil)))
|
||||
|
||||
(defn collect-page-directives
|
||||
[ast]
|
||||
(if (seq ast)
|
||||
|
@ -82,6 +116,12 @@
|
|||
(:roam_tags directives)
|
||||
(update :roam_tags sep-by-quote-or-space-or-comma))
|
||||
directives)
|
||||
definition-tags (get-tags-from-definition ast)
|
||||
directives (if definition-tags
|
||||
(update directives :tags (fn [tags]
|
||||
(-> (concat tags definition-tags)
|
||||
distinct)))
|
||||
directives)
|
||||
directives (cond-> directives
|
||||
(seq macros)
|
||||
(assoc :macros macros))
|
||||
|
|
|
@ -289,8 +289,8 @@
|
|||
(reset! last-child-end-pos old-end-pos)))
|
||||
|
||||
(cond->
|
||||
{:block/uuid uuid
|
||||
:block/meta new-meta}
|
||||
{:block/uuid uuid
|
||||
:block/meta new-meta}
|
||||
(and (some? indent-left?) (not @next-leq-level?))
|
||||
(assoc :block/level (if indent-left? (dec level) (inc level)))
|
||||
(and new-content (not @next-leq-level?))
|
||||
|
@ -403,6 +403,14 @@
|
|||
{:db/id page-id
|
||||
:page/directives new-directives}]
|
||||
[[:db/retract page-id :page/directives]]))
|
||||
pages (if (seq page-tags)
|
||||
(let [tag-pages (map
|
||||
(fn [page]
|
||||
{:page/original-name page
|
||||
:page/name page})
|
||||
(map :tag/name page-tags))]
|
||||
(concat pages tag-pages))
|
||||
pages)
|
||||
page-tags (when (and pre-block? (seq page-tags))
|
||||
(if (seq page-tags)
|
||||
[[:db/retract page-id :page/tags]
|
||||
|
|
Loading…
Reference in New Issue