Fix page tags

This commit is contained in:
Tienson Qin
2020-07-21 17:46:30 +08:00
parent d73e405b9e
commit e4e5e7254b
7 changed files with 114 additions and 65 deletions

View File

@@ -89,21 +89,9 @@
first
second))
(defn ->tags
[tags]
(->> (map (fn [tag]
(let [tag (-> (string/lower-case tag)
(string/replace #"\s+" "-"))]
(if (util/tag-valid? tag)
{:db/id tag
:tag/name tag})))
(remove nil? tags))
(remove nil?)
vec))
(defn with-refs
[{:keys [title body tags] :as heading}]
(let [tags (mapv :tag/name (->tags (map :tag/name tags)))
(let [tags (mapv :tag/name (util/->tags (map :tag/name tags)))
ref-pages (atom tags)]
(walk/postwalk
(fn [form]
@@ -130,7 +118,7 @@
[{:keys [title body tags] :as heading}]
(cond-> heading
(seq tags)
(assoc :tags (->tags tags))))
(assoc :tags (util/->tags tags))))
(defn extract-headings
[blocks last-pos encoded-content]

View File

@@ -26,19 +26,22 @@
(.parseJson js/window.Mldoc content (or config default-config))))
;; E.g "Foo Bar \"Bar Baz\""
(defn- sep-by-quote-or-space
(defn- sep-by-quote-or-space-or-comma
[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)))
(when s
(let [comma? (re-find #"," s)]
(some->>
(string/split s #"[\"|\,]{1}")
(remove string/blank?)
(map (fn [s]
(if (and (not comma?)
(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]
@@ -64,18 +67,17 @@
directives (->> (remove (fn [x] (= :macro (first x))) directives)
(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)))
(cond-> directives
(:roam_alias directives)
(assoc :alias (:roam_alias directives))
(:roam_key directives)
(assoc :key (:roam_key directives))
(:alias directives)
(update :alias sep-by-quote-or-space-or-comma)
(:tags directives)
(update :tags sep-by-quote-or-space-or-comma)
(:roam_tags directives)
(update :roam_tags sep-by-quote-or-space-or-comma))
directives)
directives (assoc directives :macros macros)
other-ast (drop-while directive? ast)]