diff --git a/bases/do-blog/src/com/oly/static_sites/do_blog/pages/helpers/database.cljc b/bases/do-blog/src/com/oly/static_sites/do_blog/pages/helpers/database.cljc index 7943c32..1ec2b76 100644 --- a/bases/do-blog/src/com/oly/static_sites/do_blog/pages/helpers/database.cljc +++ b/bases/do-blog/src/com/oly/static_sites/do_blog/pages/helpers/database.cljc @@ -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 %)))))) diff --git a/bases/do-blog/src/com/oly/static_sites/do_blog/theme.cljc b/bases/do-blog/src/com/oly/static_sites/do_blog/theme.cljc index e7d8ecf..46b76c6 100644 --- a/bases/do-blog/src/com/oly/static_sites/do_blog/theme.cljc +++ b/bases/do-blog/src/com/oly/static_sites/do_blog/theme.cljc @@ -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