add static site generator

This commit is contained in:
2025-05-07 17:14:45 -07:00
parent ae66d51f22
commit 1faa6dad4f
9 changed files with 168 additions and 0 deletions

30
www/src/build.hy Normal file
View 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)))))))))))