automatically build view-thought.hy if files in thoughts updated
This commit is contained in:
@ -30,6 +30,7 @@
|
|||||||
(defmain []
|
(defmain []
|
||||||
(setv last-compile-time (last-changed "../site"))
|
(setv last-compile-time (last-changed "../site"))
|
||||||
(setv data-dir-changed? (> (last-changed "data") last-compile-time))
|
(setv data-dir-changed? (> (last-changed "data") last-compile-time))
|
||||||
|
(setv assets-dir-changed? (> (last-changed "assets") last-compile-time))
|
||||||
(setv last-commit-newer (> (-> (check-output #[[git log -1 --format="%at"]] :shell True) (.decode) (.strip) (int)) last-compile-time))
|
(setv last-commit-newer (> (-> (check-output #[[git log -1 --format="%at"]] :shell True) (.decode) (.strip) (int)) last-compile-time))
|
||||||
|
|
||||||
(print f"last compiled: {last-compile-time :.0f}")
|
(print f"last compiled: {last-compile-time :.0f}")
|
||||||
@ -37,10 +38,21 @@
|
|||||||
(when (not (dir? "output"))
|
(when (not (dir? "output"))
|
||||||
(mkdir "output"))
|
(mkdir "output"))
|
||||||
|
|
||||||
(for [path (glob "./pages/**/*" :recursive True)]
|
;; only recompile pages when:
|
||||||
(when (in "__pycache__" path)
|
;; - the source page is newer than the output
|
||||||
(continue))
|
;; - the `src/data` directory is newer than the output
|
||||||
|
;; - the latest commit is newer than the output
|
||||||
|
;; - the page is view-thought.hy and there are thoughts being recompiled
|
||||||
|
(setv pages-to-build (lfor path (glob "./pages/**/*" :recursive True)
|
||||||
|
:if (not-in "__pycache__" path)
|
||||||
|
:if (or (> (last-changed path) (last-changed-prev-compile path)) data-dir-changed? assets-dir-changed? last-commit-newer)
|
||||||
|
path))
|
||||||
|
|
||||||
|
(when (any (map (fn [x] (in "/thoughts/" x)) pages-to-build))
|
||||||
|
(when (all (map (fn [x] (not-in "./pages/html/view-thought.hy" x)) pages-to-build))
|
||||||
|
(setv pages-to-build ["./pages/html/view-thought.hy" #* pages-to-build])))
|
||||||
|
|
||||||
|
(for [path pages-to-build]
|
||||||
(cond
|
(cond
|
||||||
(and (dir? path) (not (dir? (.replace path "pages" "output"))))
|
(and (dir? path) (not (dir? (.replace path "pages" "output"))))
|
||||||
(do
|
(do
|
||||||
@ -48,21 +60,13 @@
|
|||||||
(mkdir (.replace path "pages" "output")))
|
(mkdir (.replace path "pages" "output")))
|
||||||
|
|
||||||
(file? path)
|
(file? path)
|
||||||
;; only recompile pages when:
|
(do
|
||||||
;; - the source page is newer than the output
|
(print f"building {path}")
|
||||||
;; - the `src/data` directory is newer than the output
|
(setv page-name (.split (cut path 2 -3) "/"))
|
||||||
;; - the latest commit is newer than the output
|
(enshrine page-name)
|
||||||
(if (or (> (last-changed path) (last-changed-prev-compile path)) data-dir-changed? last-commit-newer)
|
(with [target (open (+ "./output/" (.join "/" (cut page-name 1 None)) ".html") "w")]
|
||||||
(do
|
(.write target (form->html
|
||||||
(print f"building {path}")
|
(hy-eval (hy.read (with [source (open path "r")]
|
||||||
(setv page-name (.split (cut path 2 -3) "/"))
|
(.read source)))
|
||||||
(enshrine page-name)
|
:locals local-scope
|
||||||
(with [target (open (+ "./output/" (.join "/" (cut page-name 1 None)) ".html") "w")]
|
:globals global-scope))))))))
|
||||||
(.write target (form->html
|
|
||||||
(hy-eval (hy.read (with [source (open path "r")]
|
|
||||||
(.read source)))
|
|
||||||
:locals local-scope
|
|
||||||
:globals global-scope)))))
|
|
||||||
|
|
||||||
(print f"{(.replace path #[[./pages/]] #[[../site/html/]])} more recent, skipping")))))
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user