diff --git a/src/main/backend/core.clj b/src/main/backend/core.clj index 323d10f..fed4fff 100644 --- a/src/main/backend/core.clj +++ b/src/main/backend/core.clj @@ -2,6 +2,7 @@ (:require [org.httpkit.server :as server] [reitit.ring :as ring] [backend.handlers :as handlers] + [backend.page :as page] [backend.hugo.site :as hugo]) (:gen-class)) @@ -9,7 +10,9 @@ (def app (ring/ring-handler (ring/router - [["/hp/:id" {:parameters {:path {:id int?}} + [["/" {:parameters {} + :get {:handler page/frontend-page}}] + ["/hp/:id" {:parameters {:path {:id int?}} :get {:handler hugo/build-hugo-post}}] ["/api" ["/hp/:id" {:parameters {:path {:id int?}} diff --git a/src/main/backend/handlers.clj b/src/main/backend/handlers.clj index d41242e..e91e158 100644 --- a/src/main/backend/handlers.clj +++ b/src/main/backend/handlers.clj @@ -91,7 +91,7 @@ (let [post-id (-> request :path-params :id)] (fetch-hu-post post-id {:content-type {"Content-Type" "application/json; charset=utf-8"} - :replace-str "#/item/" + :replace-str "#/hp/" :wrap-fn wrap-json}))) (defn build-answer diff --git a/src/main/backend/hugo/site.clj b/src/main/backend/hugo/site.clj index 39d2772..cbb2a2d 100644 --- a/src/main/backend/hugo/site.clj +++ b/src/main/backend/hugo/site.clj @@ -1,29 +1,28 @@ (ns backend.hugo.site (:require [backend.handlers :as handlers] - [hiccup.page :as page])) + [backend.page :as page] + [hiccup2.core :as hiccup])) -(def hugo-post-template - #(page/html5 - {:escape-strings? false} - [:html - [:head - [:meta {:name "viewport" :content "width=device-width, initial-scale=1.0"}] - [:meta {:name "referrer" :content "no-referrer"}] - (page/include-css "/css/app.css")] +(defn hugo-post-template + [content] + (page/page-template + #(hiccup/html + {:escape-strings? false} [:body [:div {:id "app"} [:div {:class "container p-2 mx-auto"} [:div {:class "flex flex-row flex-wrap py-4"} [:div {:class "w-full sm:w-1/3 md:w-1/4 px-2"} [:div {:class "sticky top-0 p-4 bg-slate-300 rounded-xl w-full"} - [:div (:catalog %)]]] + [:div (:catalog content)]]] [:div {:class "w-full sm:w-2/3 md:w-3/4 pt-1 px-2"} - [:h1 (:title %)] - [:time (:time %)] + [:h1 (:title content)] + [:time (:time content)] [:hr] [:div - (:content %)]]]]]]])) + (:content content)]]]]]] + ))) (defn build-hugo-post [request] diff --git a/src/main/backend/page.clj b/src/main/backend/page.clj new file mode 100644 index 0000000..3d40ef6 --- /dev/null +++ b/src/main/backend/page.clj @@ -0,0 +1,26 @@ +(ns backend.page + (:require [backend.handlers :as handlers] + [hiccup.page :as page])) + +(defn page-template + [body] + (page/html5 + [:head + [:meta {:charset "UTF-8"}] + [:meta {:http-equiv "X-UA-Compatible" :content= "IE=edge"}] + [:meta {:name "viewport" :content "width=device-width, initial-scale=1.0"}] + [:meta {:name "referrer" :content "no-referrer"}] + (page/include-css "/css/app.css")] + body)) + +(defn frontend-page + [_] + {:status 200 + :content-type {"Content-Type" "text/html; charset=utf-8"} + :body (page-template + [:body + [:div {:id "app"} + [:div {:class "flex flex-col items-center justify-center h-screen"} + [:div {:class "loading"}] + [:p "Loading"]]] + (page/include-js "/js/main.js")])})