[refactor] merge index page

This commit is contained in:
SouthFox 2023-09-08 21:14:01 +08:00
parent ff44684329
commit 17e3c604aa
4 changed files with 43 additions and 15 deletions

View file

@ -2,6 +2,7 @@
(:require [org.httpkit.server :as server] (:require [org.httpkit.server :as server]
[reitit.ring :as ring] [reitit.ring :as ring]
[backend.handlers :as handlers] [backend.handlers :as handlers]
[backend.page :as page]
[backend.hugo.site :as hugo]) [backend.hugo.site :as hugo])
(:gen-class)) (:gen-class))
@ -9,7 +10,9 @@
(def app (def app
(ring/ring-handler (ring/ring-handler
(ring/router (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}}] :get {:handler hugo/build-hugo-post}}]
["/api" ["/api"
["/hp/:id" {:parameters {:path {:id int?}} ["/hp/:id" {:parameters {:path {:id int?}}

View file

@ -91,7 +91,7 @@
(let [post-id (-> request :path-params :id)] (let [post-id (-> request :path-params :id)]
(fetch-hu-post post-id (fetch-hu-post post-id
{:content-type {"Content-Type" "application/json; charset=utf-8"} {:content-type {"Content-Type" "application/json; charset=utf-8"}
:replace-str "#/item/" :replace-str "#/hp/"
:wrap-fn wrap-json}))) :wrap-fn wrap-json})))
(defn build-answer (defn build-answer

View file

@ -1,29 +1,28 @@
(ns backend.hugo.site (ns backend.hugo.site
(:require [backend.handlers :as handlers] (:require [backend.handlers :as handlers]
[hiccup.page :as page])) [backend.page :as page]
[hiccup2.core :as hiccup]))
(def hugo-post-template (defn hugo-post-template
#(page/html5 [content]
(page/page-template
#(hiccup/html
{:escape-strings? false} {: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")]
[:body [:body
[:div {:id "app"} [:div {:id "app"}
[:div {:class "container p-2 mx-auto"} [:div {:class "container p-2 mx-auto"}
[:div {:class "flex flex-row flex-wrap py-4"} [: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 "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 {: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"} [:div {:class "w-full sm:w-2/3 md:w-3/4 pt-1 px-2"}
[:h1 (:title %)] [:h1 (:title content)]
[:time (:time %)] [:time (:time content)]
[:hr] [:hr]
[:div [:div
(:content %)]]]]]]])) (:content content)]]]]]]
)))
(defn build-hugo-post (defn build-hugo-post
[request] [request]

26
src/main/backend/page.clj Normal file
View file

@ -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")])})