summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-03-17 16:55:29 +0800
committereltrac <hi@eltr.ac>2026-03-17 16:55:29 +0800
commitfbfbeea819a764e3ec2b2505a33abfede6983b07 (patch)
tree68c8b638c243ea6ec2cb73183a50ada3bcf3f13e /src
parent6036e6f8b2b3e29b6f36b530a6d729417daabc31 (diff)
feat(ui): add homepage
Diffstat (limited to 'src')
-rw-r--r--src/weepinbell/handler.clj3
-rw-r--r--src/weepinbell/ui.clj32
-rw-r--r--src/weepinbell/utils.clj9
3 files changed, 44 insertions, 0 deletions
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)))))
+