86 lines
2.9 KiB
Clojure
86 lines
2.9 KiB
Clojure
(ns com.biffweb.my-project.ui
|
|
(:require [cheshire.core :as cheshire]
|
|
[com.biffweb.my-project.settings :as settings]
|
|
[ring.middleware.anti-forgery :as csrf]
|
|
[rum.core :as rum]))
|
|
|
|
(defn the-base-html
|
|
[{:base/keys [title
|
|
description
|
|
lang
|
|
image
|
|
icon
|
|
url
|
|
canonical
|
|
_font-families
|
|
head]}
|
|
& contents]
|
|
[:html
|
|
{:lang lang
|
|
:style {:min-height "100%"
|
|
:height "auto"}}
|
|
[:head
|
|
[:title title]
|
|
[:meta {:name "description" :content description}]
|
|
[:meta {:content title :property "og:title"}]
|
|
[:meta {:content description :property "og:description"}]
|
|
(when image
|
|
[:<>
|
|
[:meta {:content image :property "og:image"}]
|
|
[:meta {:content "summary_large_image" :name "twitter:card"}]])
|
|
(when-some [url (or url canonical)]
|
|
[:meta {:content url :property "og:url"}])
|
|
(when-some [url (or canonical url)]
|
|
[:link {:ref "canonical" :href url}])
|
|
[:meta {:name "viewport" :content "width=device-width, initial-scale=1"}]
|
|
(when icon
|
|
[:link {:rel "icon"
|
|
:type "image/png"
|
|
:sizes "16x16"
|
|
:href icon}])
|
|
[:meta {:charset "utf-8"}]
|
|
(into [:<>] head)]
|
|
[:body
|
|
[:main.container
|
|
contents]]])
|
|
|
|
(defn base [ctx & body]
|
|
(apply
|
|
the-base-html
|
|
(-> ctx
|
|
(merge #:base{:title settings/app-name
|
|
:lang "en-US"
|
|
:icon "/img/glider.png"
|
|
:description (str settings/app-name " Description")
|
|
:image "https://clojure.org/images/clojure-logo-120b.png"})
|
|
(update :base/head (fn [head]
|
|
(concat [[:link {:rel "stylesheet" :href "/css/pico.min.css"}]
|
|
[:link {:rel "stylesheet" :href "/css/pico.colors.min.css"}]
|
|
[:link {:rel "stylesheet" :href "/css/my.css"}]
|
|
[:script {:src "/js/main.js"}]
|
|
[:script {:src "/js/htmx-1.9.11.min.js"}]
|
|
[:script {:src "/js/htmx-1.9.11-ext-ws.min.js"}]
|
|
[:script {:src "/js/htmx-1.9.11-ext-multi-swap.min.js"}]
|
|
[:script {:src "/js/hyperscript-0.9.8.min.js"}]]
|
|
head))))
|
|
body))
|
|
|
|
(defn page [ctx & body]
|
|
(base
|
|
ctx
|
|
[:div
|
|
(when (bound? #'csrf/*anti-forgery-token*)
|
|
{:hx-headers (cheshire/generate-string
|
|
{:x-csrf-token csrf/*anti-forgery-token*})})
|
|
body]))
|
|
|
|
(defn on-error [{:keys [status _ex] :as ctx}]
|
|
{:status status
|
|
:headers {"content-type" "text/html"}
|
|
:body (rum/render-static-markup
|
|
(page
|
|
ctx
|
|
[:h1
|
|
(if (= status 404)
|
|
"Page not found."
|
|
"Something went wrong.")]))})
|