88 lines
2.4 KiB
Janet
88 lines
2.4 KiB
Janet
(import janet-html :as html)
|
|
(import spork/netrepl)
|
|
|
|
(import ./views)
|
|
(import ./utils)
|
|
|
|
# disable pretty-printing
|
|
|
|
(setdyn :pretty-format "%.20q")
|
|
|
|
# ---
|
|
# build config
|
|
# ---
|
|
|
|
(def base-path "/")
|
|
(bagatto/set-output-dir! "site")
|
|
|
|
# ---
|
|
# helper functions
|
|
# ---
|
|
|
|
(defn struct->table [s]
|
|
(table ;(interleave (keys s) (values s))))
|
|
|
|
(defn path->date [path]
|
|
(let [datestr (->>
|
|
(string/split "/" path)
|
|
(last)
|
|
(string/split "--")
|
|
(first))
|
|
date (struct->table (bagatto/datestr->date datestr true))]
|
|
# we have to massage the struct a bit because by default the date is
|
|
# interpreted as a local date and converted to UTC.
|
|
# NOTE: we don't fix year-day because we'd have to check for leap years.
|
|
(put date :hours 0)
|
|
(update date :month-day inc)
|
|
(update date :week-day (comp |(mod $0 7) inc))))
|
|
|
|
(defn parse-post [slurped item]
|
|
(let [post (bagatto/parse-mmarkdown slurped item) ]
|
|
(put post :published-at (path->date (post :path)))
|
|
post))
|
|
|
|
(defn absolute-url [path]
|
|
(string base-path path))
|
|
|
|
(defn copy-and-rename [base renamer]
|
|
(fn [_data item] (path/join base (path/basename (renamer (item :path))))))
|
|
|
|
(defn sass? [_site item]
|
|
(or (string/has-suffix? ".scss" (item :path))
|
|
(string/has-suffix? ".sass" (item :path))))
|
|
|
|
(defn compile-sass [site {:path path}]
|
|
(sh/$< "sassc" ,(string path)))
|
|
|
|
(def sass-dest (copy-and-rename "assets/"
|
|
(fn [path]
|
|
(->> path
|
|
(string/replace ".sass" ".css")
|
|
(string/replace ".scss" ".css")))))
|
|
|
|
# ---
|
|
# site config
|
|
# ---
|
|
|
|
(def data {:config {:attrs {:title "arnes.space"
|
|
:base-path base-path
|
|
:stylesheet (absolute-url "assets/style.css")}}
|
|
:assets {:src (bagatto/* "assets/*")
|
|
:attrs bagatto/parse-base}
|
|
:posts {:src (bagatto/slurp-* "content/posts/*.md")
|
|
:attrs parse-post}})
|
|
|
|
(def site {:index {:dest "index.html"
|
|
:out views/home}
|
|
:style {:each :assets
|
|
:dest sass-dest
|
|
:out compile-sass
|
|
:filter sass?}
|
|
:posts {:each :posts
|
|
:dest utils/slugify-content
|
|
:out views/post}})
|
|
|
|
(comment
|
|
(->>
|
|
(eval-data data)
|
|
(eval-site site)))
|