(ns bengine.tags
  (:require [clojure.string :as str]))

(def moment (js/require "moment"))

(defn ->date [js-date]
  (.format (moment creation-time) "LL"))

;; common wrapper for all pages
(defn html [& forms]
  [:html
   [:head
    [:meta {:charset "utf-8"}]
    [:meta {:name "viewport"
            :content "width=device-width, initial-scale=1"}]
    [:link {:rel "stylesheet"
            :href "-css/1.1/tufte.min.css"}]]
   [:body forms]])

;; wrapper for the index page (home page)
(defn index [post-infos]
  (html
    [:article
     [:h1 "My Blog"]
     [:p "Welcome or some-such."]
     (into
       [:ul]
       ;; Example post info:
       (for [{:keys [here title creation-time]}
             post-infos]
         [:li
          [:a {:href here} title]
          [:span " - (posted on: " (->date creation-time) ")"]]))]))

;; wrapper common to all posts
(defn post [content {:keys [title creation-time here next prev up]}]
  (html
    [:h1 [:a {:href here} title]]
    [:span "Posted on: " (->date creation-time)]
    content
    (when prev
      [:a {:href prev} "<--"])
    [:span {:style "margin: auto 10px;"}
     [:a {:href up} "back"]]
    (when next
      [:a {:href next} "-->"])))

;; user's own tags:
(defn title [s] [:h1 s])

(defn p [& xs]
  [:p (str/join \newline xs)])

 common wrapper for all pages
 wrapper for the index page (home page)
 Example post info:
 wrapper common to all posts
 user's own tags:
(ns bengine.tags
  (:require [clojure.string :as str]))

(def moment (js/require "moment"))

(defn ->date [js-date]
  (.format (moment creation-time) "LL"))

(defn html [& forms]
  [:html
   [:head
    [:meta {:charset "utf-8"}]
    [:meta {:name "viewport"
            :content "width=device-width, initial-scale=1"}]
    [:link {:rel "stylesheet"
            :href "-css/1.1/tufte.min.css"}]]
   [:body forms]])

(defn index [post-infos]
  (html
    [:article
     [:h1 "My Blog"]
     [:p "Welcome or some-such."]
     (into
       [:ul]
       (for [{:keys [here title creation-time]}
             post-infos]
         [:li
          [:a {:href here} title]
          [:span " - (posted on: " (->date creation-time) ")"]]))]))

(defn post [content {:keys [title creation-time here next prev up]}]
  (html
    [:h1 [:a {:href here} title]]
    [:span "Posted on: " (->date creation-time)]
    content
    (when prev
      [:a {:href prev} "<--"])
    [:span {:style "margin: auto 10px;"}
     [:a {:href up} "back"]]
    (when next
      [:a {:href next} "-->"])))

(defn title [s] [:h1 s])

(defn p [& xs]
  [:p (str/join \newline xs)])
