forked from nat/natalieee.net
add static site generator
This commit is contained in:
30
www/src/build.hy
Normal file
30
www/src/build.hy
Normal file
@ -0,0 +1,30 @@
|
||||
(import glob [glob])
|
||||
(import os [mkdir])
|
||||
(import os.path [isfile :as file? isdir :as dir?])
|
||||
(import templates *)
|
||||
(import utils *)
|
||||
|
||||
(require hyrule.control [defmain])
|
||||
|
||||
(defmain []
|
||||
(when (not (dir? "output"))
|
||||
(mkdir "output"))
|
||||
|
||||
(for [path (glob "./pages/**/*" :recursive True)]
|
||||
(when (in "__pycache__" path)
|
||||
(continue))
|
||||
|
||||
(cond
|
||||
(and (dir? path) (not (dir? (.replace path "pages" "output"))))
|
||||
(do
|
||||
(print f"creating {path}")
|
||||
(mkdir (.replace path "pages" "output")))
|
||||
|
||||
(file? path)
|
||||
(do
|
||||
(print f"building {path}")
|
||||
(setv page-name (.split (cut path 2 -3) "/"))
|
||||
(with [target (open (+ "./output/" (.join "/" (cut page-name 1 None)) ".html") "w")]
|
||||
(.write target (form->html
|
||||
(hy.eval (hy.read (with [source (open path "r")]
|
||||
(.read source)))))))))))
|
Reference in New Issue
Block a user