diff options
| author | eltrac <hi@eltr.ac> | 2026-03-17 16:55:29 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-03-17 16:55:29 +0800 |
| commit | fbfbeea819a764e3ec2b2505a33abfede6983b07 (patch) | |
| tree | 68c8b638c243ea6ec2cb73183a50ada3bcf3f13e | |
| parent | 6036e6f8b2b3e29b6f36b530a6d729417daabc31 (diff) | |
feat(ui): add homepage
| -rw-r--r-- | project.clj | 3 | ||||
| -rw-r--r-- | resources/static/main.css | 18 | ||||
| -rw-r--r-- | src/weepinbell/handler.clj | 3 | ||||
| -rw-r--r-- | src/weepinbell/ui.clj | 32 | ||||
| -rw-r--r-- | src/weepinbell/utils.clj | 9 |
5 files changed, 64 insertions, 1 deletions
diff --git a/project.clj b/project.clj index f151068..6934879 100644 --- a/project.clj +++ b/project.clj @@ -13,7 +13,8 @@ [clj-http "3.13.1"] [com.kylewm/mf2j "0.0.4"] [com.taoensso/timbre "6.8.0"] - [digest "1.4.10"]] + [digest "1.4.10"] + [hiccup "2.0.0"]] :plugins [[lein-ring "0.12.5"]] :ring {:handler weepinbell.handler/app} :main ^:skip-aot weepinbell.core diff --git a/resources/static/main.css b/resources/static/main.css new file mode 100644 index 0000000..4ed14ae --- /dev/null +++ b/resources/static/main.css @@ -0,0 +1,18 @@ +.home { + display: flex; + align-items: center; + justify-content: center; + min-height: 100dvh; + flex-direction: column; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; +} + +.home img.banner { + display: block; + width: 400px; +} + +.home p { + text-align: center; +} + diff --git a/src/weepinbell/handler.clj b/src/weepinbell/handler.clj index 7194875..056c8f4 100644 --- a/src/weepinbell/handler.clj +++ b/src/weepinbell/handler.clj @@ -8,6 +8,7 @@ [weepinbell.receiver :refer [receive]] [weepinbell.retriever :as retriever] [weepinbell.processor :refer [process-webmention]] + [weepinbell.ui :as ui] [clojure.core.async :refer [chan]])) (def wmc (chan)) @@ -15,6 +16,8 @@ (process-webmention wmc) (defroutes api-routes + (GET "/" [] (ui/home (get-config :allowed-target-domains) + (get-config :endpoint))) ;; receiver endpoint (POST (get-config :endpoint) [source target] (receive {:s source :t target} wmc)) diff --git a/src/weepinbell/ui.clj b/src/weepinbell/ui.clj new file mode 100644 index 0000000..a8abacd --- /dev/null +++ b/src/weepinbell/ui.clj @@ -0,0 +1,32 @@ +(ns weepinbell.ui + (:require [hiccup2.core :as h] + [weepinbell.utils :refer [format-list]])) + +(defn- page-response [page] + {:body page + :headers {"Content-Type" "text/html"} + :status 200}) + +(defn- page-base [slot] + (str (h/html [:html + [:head + [:link {:rel "stylesheet" :href "/main.css"}] + [:title "Weepinbell - Webmention Receiver"]] + [:body slot]]))) + +(defn home [domains endpoint] + (-> + [:main.home + [:img.banner {:src "/weepinbell.avif"}] + [:div + [:p "This is a " [:a {:href "https://codeberg.org/eltrac/weepinbell" :target "_blank"} "Weepinbell"] "."] + [:p "He receives " [:a {:href "https://indieweb.org/webmention" :target "_blank"}] " for " (format-list domains)]] + [:div + [:p "Have him send a Webmention for you."] + [:form {:action endpoint :method "POST"} + [:input {:name "source" :placeholder "source"}] + [:input {:name "target" :placeholder "target"}] + [:button {:type "submit"} "send"]]]] + page-base + page-response)) + diff --git a/src/weepinbell/utils.clj b/src/weepinbell/utils.clj index 8c3a21a..6012a5e 100644 --- a/src/weepinbell/utils.clj +++ b/src/weepinbell/utils.clj @@ -100,3 +100,12 @@ :headers {"Content-Type" "application/json; charset=utf-8"} :body json-string}))) +(defn format-list [coll] + (let [total (count coll)] + (cond + (= total 0) "" + (= total 1) (first coll) + :else (str (clojure.string/join ", " (butlast coll)) + " and " + (last coll))))) + |
