Split views into separate file
This commit is contained in:
parent
6ab73f71df
commit
1b776bd0f3
2 changed files with 20 additions and 10 deletions
13
index.janet
13
index.janet
|
|
@ -1,8 +1,7 @@
|
||||||
(import janet-html :as html)
|
(import janet-html :as html)
|
||||||
(import path)
|
(import path)
|
||||||
|
|
||||||
(defn as-html [h]
|
(import ./views)
|
||||||
(html/encode (html/doctype :html5) [:html h]))
|
|
||||||
|
|
||||||
(bagatto/set-output-dir! "site")
|
(bagatto/set-output-dir! "site")
|
||||||
|
|
||||||
|
|
@ -10,15 +9,9 @@
|
||||||
:posts {:src (bagatto/slurp-* "posts/*.md")
|
:posts {:src (bagatto/slurp-* "posts/*.md")
|
||||||
:attrs bagatto/parse-mmarkdown}})
|
:attrs bagatto/parse-mmarkdown}})
|
||||||
|
|
||||||
(defn header [data]
|
|
||||||
[:head
|
|
||||||
[:meta {:charset "utf-8"}]
|
|
||||||
[:title (get-in data [:config :title])]])
|
|
||||||
|
|
||||||
(def site {:index {:dest "index.html"
|
(def site {:index {:dest "index.html"
|
||||||
:out (fn [data]
|
:out (views/base data [:h1 "Hello World!"])}
|
||||||
(as-html [(header data) [:body [:h1 "Hello World"]]]))}
|
|
||||||
:posts {:each :posts
|
:posts {:each :posts
|
||||||
:dest (bagatto/%p "posts" '%i "title" '% ".html")
|
:dest (bagatto/%p "posts" '%i "title" '% ".html")
|
||||||
:out (fn [data item]
|
: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))))}})
|
||||||
|
|
|
||||||
17
views.janet
Normal file
17
views.janet
Normal file
|
|
@ -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)]]))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue