Fix the search spo it works on all pages.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
f6e5f3f60a
commit
0b47b9ca40
|
|
@ -24,25 +24,25 @@
|
||||||
[(get-else $ ?e :thumbnail :nil) ?thumbnail]
|
[(get-else $ ?e :thumbnail :nil) ?thumbnail]
|
||||||
[?e :relative-path ?path]]})
|
[?e :relative-path ?path]]})
|
||||||
|
|
||||||
(defn escape-regex
|
|
||||||
"Escape regex special characters so user input is matched literally."
|
|
||||||
[text]
|
|
||||||
(str/replace text #"[.*+?^${}()|\[\]\\]" #(str "\\" %)))
|
|
||||||
|
|
||||||
(defn db-search-filter
|
(defn db-search-filter
|
||||||
"Add where clauses to the datalog query when supplied"
|
"Add a tag clause to the datalog query when supplied. Title search is done
|
||||||
[{:keys [search tag]}]
|
in title-matches? instead: a regex predicate clause inside the query breaks
|
||||||
(let [re-search (when-not (str/blank? search)
|
under advanced compilation (re-find is handed a non-string)."
|
||||||
(re-pattern (str "(?i)" (escape-regex search))))]
|
[{:keys [tag]}]
|
||||||
(cond-> db-search
|
(cond-> db-search
|
||||||
(not (str/blank? tag))
|
(not (str/blank? tag))
|
||||||
(update-in [:where] #(conj % ['?e :tags tag]))
|
(update-in [:where] #(conj % ['?e :tags tag]))))
|
||||||
re-search
|
|
||||||
(update-in [:where] #(conj % [`(~'re-find ~re-search ~'?title)])))))
|
|
||||||
|
|
||||||
(defn search-articles [search]
|
(defn title-matches?
|
||||||
(->> (d/q (db-search-filter search) @conn)
|
"Case-insensitive, literal substring match of the search terms on the title."
|
||||||
|
[search {:keys [title]}]
|
||||||
|
(or (str/blank? search)
|
||||||
|
(str/includes? (str/lower-case (str title)) (str/lower-case search))))
|
||||||
|
|
||||||
|
(defn search-articles [{:keys [search] :as query}]
|
||||||
|
(->> (d/q (db-search-filter query) @conn)
|
||||||
(flatten)
|
(flatten)
|
||||||
|
(filter #(title-matches? search %))
|
||||||
(sort-by :date)
|
(sort-by :date)
|
||||||
reverse
|
reverse
|
||||||
(map #(assoc % :relative-path (ltrim-slash (:relative-path %))))))
|
(map #(assoc % :relative-path (ltrim-slash (:relative-path %))))))
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@
|
||||||
(def tachyon-theme
|
(def tachyon-theme
|
||||||
{:TITLE :header.f2.fw6.f2-ns.lh-title.mt0.mb2
|
{:TITLE :header.f2.fw6.f2-ns.lh-title.mt0.mb2
|
||||||
;:DESCRIPTION :p
|
;:DESCRIPTION :p
|
||||||
:HEADER1 :h1.f3.fw6.f3-ns.lh-title.mt0.mb2
|
:HEADER1 :h1.f3.fw6.f3-ns.lh-title.mt0.mb2.mb4
|
||||||
:HEADER2 :h2.f3.fw6.f3-ns.lh-title.mt0.mb2
|
:HEADER2 :h2.f3.fw6.f3-ns.lh-title.mt0.mb2.mb4
|
||||||
:HEADER3 :h3
|
:HEADER3 :h3
|
||||||
:HEADER4 :h4
|
:HEADER4 :h4
|
||||||
:HEADER5 :h5
|
:HEADER5 :h5
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue