summaryrefslogtreecommitdiffstats
path: root/src/view/main.phel
blob: f7a01908a5cd653e4f26348f5843507b2936e4f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(ns lezer.view.main
  (:require phel.router :as r)
  (:require phel.html :refer [html doctype raw-string])
  (:require phel.string :as str))

(def- head
  [:head
   [:meta {:charset "utf-8"}]
   [:meta {:name "viewport" :content "width=device-width, initial-scale=1"}]
   [:link {:rel "stylesheet" :href "./css/style.css"}]
   [:link {:rel "icon" :type "image/png" :href "./images/favicon-32.png"}]
   [:title "Lezer"]])

(def- logo
  [:div {:class "logo"}
   [:img {:src "./images/logo.svg" :width "360"}]])

(def- links
  [:div {:class "links"}
   [:a {:href "https://phel-lang.org/"} "Homepage"]
   [:a {:href "https://phel-lang.org/documentation/getting-started/"} "Getting started"]
   [: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
     [: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))