From 1b776bd0f3fa5c11827d627065d0e61ce1cb3992 Mon Sep 17 00:00:00 2001 From: heyarne Date: Sat, 10 Jul 2021 10:30:25 +0200 Subject: [PATCH] Split views into separate file --- index.janet | 13 +++---------- views.janet | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 views.janet diff --git a/index.janet b/index.janet index f1c7c55..c1d6a34 100644 --- a/index.janet +++ b/index.janet @@ -1,8 +1,7 @@ (import janet-html :as html) (import path) -(defn as-html [h] - (html/encode (html/doctype :html5) [:html h])) +(import ./views) (bagatto/set-output-dir! "site") @@ -10,15 +9,9 @@ :posts {:src (bagatto/slurp-* "posts/*.md") :attrs bagatto/parse-mmarkdown}}) -(defn header [data] - [:head - [:meta {:charset "utf-8"}] - [:title (get-in data [:config :title])]]) - (def site {:index {:dest "index.html" - :out (fn [data] - (as-html [(header data) [:body [:h1 "Hello World"]]]))} + :out (views/base data [:h1 "Hello World!"])} :posts {:each :posts :dest (bagatto/%p "posts" '%i "title" '% ".html") :out (fn [data item] - (as-html [(header data) [:body (html/raw (bagatto/mmarkdown->html (item :contents)))]]))}}) + (views/with-raw-html data (bagatto/mmarkdown->html (item :contens))))}}) diff --git a/views.janet b/views.janet new file mode 100644 index 0000000..d2a95f2 --- /dev/null +++ b/views.janet @@ -0,0 +1,17 @@ +(import janet-html :as html) + +(defn as-html [h] + (html/encode (html/doctype :html5) [:html h])) + +(defn header [data] + [:head + [:meta {:charset "utf-8"}] + [:title (get-in data [:config :title])]]) + +(defn base [data body] + (as-html [(header data) + [:body body]])) + +(defn with-raw-html [data raw-html] + (as-html [(header data) + [:body (html/raw raw-html)]]))