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]
|
||||
[?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
|
||||
"Add where clauses to the datalog query when supplied"
|
||||
[{:keys [search tag]}]
|
||||
(let [re-search (when-not (str/blank? search)
|
||||
(re-pattern (str "(?i)" (escape-regex search))))]
|
||||
(cond-> db-search
|
||||
(not (str/blank? tag))
|
||||
(update-in [:where] #(conj % ['?e :tags tag]))
|
||||
re-search
|
||||
(update-in [:where] #(conj % [`(~'re-find ~re-search ~'?title)])))))
|
||||
"Add a tag clause to the datalog query when supplied. Title search is done
|
||||
in title-matches? instead: a regex predicate clause inside the query breaks
|
||||
under advanced compilation (re-find is handed a non-string)."
|
||||
[{:keys [tag]}]
|
||||
(cond-> db-search
|
||||
(not (str/blank? tag))
|
||||
(update-in [:where] #(conj % ['?e :tags tag]))))
|
||||
|
||||
(defn search-articles [search]
|
||||
(->> (d/q (db-search-filter search) @conn)
|
||||
(defn title-matches?
|
||||
"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)
|
||||
(filter #(title-matches? search %))
|
||||
(sort-by :date)
|
||||
reverse
|
||||
(map #(assoc % :relative-path (ltrim-slash (:relative-path %))))))
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
(def tachyon-theme
|
||||
{:TITLE :header.f2.fw6.f2-ns.lh-title.mt0.mb2
|
||||
;:DESCRIPTION :p
|
||||
:HEADER1 :h1.f3.fw6.f3-ns.lh-title.mt0.mb2
|
||||
:HEADER2 :h2.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.mb4
|
||||
:HEADER3 :h3
|
||||
:HEADER4 :h4
|
||||
:HEADER5 :h5
|
||||
|
|
|
|||
Loading…
Reference in New Issue