diff --git a/public/index.html b/public/index.html index 2568fa1..d5295aa 100644 --- a/public/index.html +++ b/public/index.html @@ -93,6 +93,47 @@ padding: 0 0 36px; } + section.posts .controls .search-form input { + width: 80%; + } + + @media screen and (min-width: 640px) { + section.posts .controls { + display: grid; + grid-template: + "a a" + "b c"; + } + + section.posts .controls .post-info { + grid-area: a; + } + + section.posts .controls .search-form { + grid-area: b; + } + + section.posts .controls .search-form input { + width: auto; + } + + section.posts .controls .buttons { + grid-area: c; + display: flex; + justify-content: end; + } + } + + section.posts .controls .control-button { + padding: 6px; + margin: 6px 0; + background: #f5e6ab; + color: #444; + cursor: pointer; + text-decoration: none; + display: inline-block; + } + section.posts ul.results { margin: 0; padding: 0; @@ -132,17 +173,6 @@ list-style-type: none; } - section.posts .post .controls .control-element a { - padding: 6px; - margin: 0 0 6px 6px; - background: #f5e6ab; - color: #444; - cursor: pointer; - text-decoration: none; - display: inline-block; - } - - @media screen and (min-width: 640px) { section.posts .post .controls { display: flex; @@ -162,6 +192,20 @@ color: #eee; margin: .16rem; } + + blockquote { + margin-left: 0; + padding: 16px 0 16px 24px; + border-left: 3px solid #f5e6ab; + } + + blockquote p:first-child { + margin-top: 0; + } + + blockquote p:last-child { + margin-bottom: 0; + } diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 20eac55..66efef3 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -15,4 +15,10 @@ {:frontend {:target :browser :modules {:main {:init-fn computersandblues.lodestone.app/init}} - :js-options {:entry-keys ["module" "browser" "main"]}}}} + :js-options {:entry-keys ["module" "browser" "main"]}} + + :test + {:target :node-test + :output-to "public/js/tests.js" + :ns-regexp "-test$" + :autorun true}}} diff --git a/src/computersandblues/lodestone/match.cljs b/src/computersandblues/lodestone/match.cljs index 669694f..e964cb1 100644 --- a/src/computersandblues/lodestone/match.cljs +++ b/src/computersandblues/lodestone/match.cljs @@ -1,16 +1,23 @@ (ns computersandblues.lodestone.match (:require [applied-science.js-interop :as j])) -(defn ->regex [s] +(defn- ->regex + "Does its best to compila a stirng into a regular expression; will fall back + to return a RegExp that matches verbatim." + [s] (try (js/RegExp. s "i") (catch js/Error _ (js/RegExp. (js/RegExp.escape s) "i")))) +(defn query->tokens [query] + (->> (re-seq #"\"([^\"]+)\"|([^\s]+)" query) + (mapv (fn [[_ a b]] (or a b))))) + (defn query->matching-fn [query] (let [match? (if query - (partial re-find (->regex query)) - (constantly true))] + (partial re-find (->regex query)) + (constantly true))] (fn [post] (or (match? (j/get post :content)) (match? (j/get-in post [:account :acct])) ; search for url + username of poster diff --git a/src/computersandblues/lodestone/match_test.cljs b/src/computersandblues/lodestone/match_test.cljs new file mode 100644 index 0000000..79a68fd --- /dev/null +++ b/src/computersandblues/lodestone/match_test.cljs @@ -0,0 +1,13 @@ +(ns computersandblues.lodestone.match-test + (:require [cljs.test :refer-macros [deftest testing is]] + [computersandblues.lodestone.match :as match])) + +(def fixtures + (clj->js [])) + +(deftest query->tokens + (testing "split words on whitespace" + (is (= ["foo" "bar"] (match/query->tokens "foo bar"))) + (is (= ["xxxx" "yyyyy"] (match/query->tokens "xxxx yyyyy")))) + (testing "quotes can be used to group tokens" + (is (= ["foo" "bar baz"] (match/query->tokens "foo \"bar baz\"")))))