From 1cf05f45874fca19706d66bbcd8d80ec851a959d Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 27 Aug 2026 00:07:02 -0700 Subject: Clean up Authors --- src/view/main.phel | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'src/view') diff --git a/src/view/main.phel b/src/view/main.phel index 9476591..f7a0190 100644 --- a/src/view/main.phel +++ b/src/view/main.phel @@ -1,6 +1,6 @@ (ns lezer.view.main (:require phel.router :as r) - (:require phel.html :refer [html doctype]) + (:require phel.html :refer [html doctype raw-string]) (:require phel.string :as str)) (def- head @@ -22,26 +22,39 @@ [:a {:href "https://github.com/phel-lang/phel-lang"} "GitHub"] [:a {:href "https://gitter.im/phel-lang/community"} "Community"]]) +(defn- authors-list [authors router] + (raw-string (html [:span + (let [a (first authors)] + (if a + [:a {:href (r/generate router :author {:id (:id (first authors))})} (:name (first authors))])) + (for [a :in (rest authors)] + [:span ", " + [:a {:href (r/generate router :author {:id (:id a)})} (:name a)]])]))) + (defn content [books router] (html (doctype :html5) [:html head [:body - [:ul - (for [b :in books] - [:li (:title (:book b)) - " by " - (for [a :in (:authors b)] - [:a {:href (r/generate router :author {:id (:id a)})} (:name a)])])] - [:div {:class "flex-center position-ref full-height"} - [:form {:action "/book" :method "POST"} - [:label {:for "title"} "Title: "] - [:input {:type "text" :name "title"}] - [:br] - [:label {:for "author"} "Author: "] - [:input {:type "text" :name "author"}] - [:input {:type "submit"}]]]]])) + [:header + [:h1 "Lezer"]] + [:main + [:ul + (for [b :in books] + [:li (:title (:book b)) + " by " + (authors-list (:authors b) router)])]] + [:aside + [:h2 "Add new book"] + [:div {:class "flex-center position-ref full-height"} + [:form {:action "/book" :method "POST"} + [:label {:for "title"} "Title: "] + [:input {:type "text" :name "title"}] + [:br] + [:label {:for "author"} "Author: "] + [:input {:type "text" :name "author"}] + [:input {:type "submit"}]]]]]])) (defn index-html [books router] (content books router)) -- cgit v1.3-2-g0d8e