This commit is contained in:
49
build-site.el
Normal file → Executable file
49
build-site.el
Normal file → Executable file
@@ -38,6 +38,19 @@ redefine site-root themselves.")
|
||||
"Expand PATH relative to `z/site-root'."
|
||||
(expand-file-name path z/site-root))
|
||||
|
||||
(defconst z/output-root
|
||||
(file-name-as-directory
|
||||
(expand-file-name
|
||||
(or (getenv "SITE_OUTPUT_DIR")
|
||||
(site-path "output/"))))
|
||||
"Absolute path to the site output directory.
|
||||
Defaults to output/ under `z/site-root', but CI can set SITE_OUTPUT_DIR to
|
||||
publish into a stable directory instead of the runner's transient checkout.")
|
||||
|
||||
(defun output-path (path)
|
||||
"Expand PATH relative to `z/output-root'."
|
||||
(expand-file-name path z/output-root))
|
||||
|
||||
(add-to-list 'load-path (site-path "lisp"))
|
||||
|
||||
;; ─────────────────────────────────────────────────────────────────────────────
|
||||
@@ -137,6 +150,8 @@ FMT / ARGS are passed to `format'."
|
||||
(require 'ox-html)
|
||||
(require 'ox-md)
|
||||
|
||||
(setq org-publish-timestamp-directory (site-path ".org-timestamps/"))
|
||||
|
||||
;; ─────────────────────────────────────────────────────────────────────────────
|
||||
;; 4. Local library requires (after load-path is set)
|
||||
;; ─────────────────────────────────────────────────────────────────────────────
|
||||
@@ -489,7 +504,7 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
:recursive t
|
||||
:base-directory ,(site-path "")
|
||||
:publishing-function z/z-publish-to-html
|
||||
:publishing-directory ,(site-path "output/")
|
||||
:publishing-directory ,(output-path "")
|
||||
:base-extension "org"
|
||||
:auto-sitemap t
|
||||
:sitemap-filename "sitemap.org"
|
||||
@@ -503,14 +518,14 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
("org-assets"
|
||||
:base-directory ,(site-path "assets/")
|
||||
:base-extension "css\\|js\\|png\\|jpg\\|jpeg\\|gif\\|webp\\|svg\\|pdf\\|mp4\\|webm\\|mov\\|woff\\|woff2\\|ttf"
|
||||
:publishing-directory ,(site-path "output/assets/")
|
||||
:publishing-directory ,(output-path "assets/")
|
||||
:recursive t
|
||||
:publishing-function org-publish-attachment)
|
||||
|
||||
("org-categories-sitemap"
|
||||
:recursive t
|
||||
:base-directory ,(site-path "home/")
|
||||
:publishing-directory ,(site-path "output/home/")
|
||||
:publishing-directory ,(output-path "home/")
|
||||
:base-extension "org"
|
||||
:auto-sitemap t
|
||||
:sitemap-filename "categories.org"
|
||||
@@ -522,7 +537,7 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
|
||||
("org-posts"
|
||||
:base-directory ,(site-path "posts/")
|
||||
:publishing-directory ,(site-path "output/posts/")
|
||||
:publishing-directory ,(output-path "posts/")
|
||||
:recursive t
|
||||
:base-extension "org"
|
||||
:publishing-function z/z-publish-to-html
|
||||
@@ -543,7 +558,7 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
|
||||
("org-blogs"
|
||||
:base-directory ,(site-path "blogs/")
|
||||
:publishing-directory ,(site-path "output/blogs/")
|
||||
:publishing-directory ,(output-path "blogs/")
|
||||
:recursive t
|
||||
:base-extension "org"
|
||||
:publishing-function z/z-publish-to-html
|
||||
@@ -562,7 +577,7 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
|
||||
("org-books"
|
||||
:base-directory ,(site-path "books/")
|
||||
:publishing-directory ,(site-path "output/books/")
|
||||
:publishing-directory ,(output-path "books/")
|
||||
:recursive t
|
||||
:base-extension "org"
|
||||
:publishing-function z/z-publish-to-html
|
||||
@@ -578,7 +593,7 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
|
||||
("org-career"
|
||||
:base-directory ,(site-path "posts/career/")
|
||||
:publishing-directory ,(site-path "output/posts/career/")
|
||||
:publishing-directory ,(output-path "posts/career/")
|
||||
:recursive t
|
||||
:base-extension "org"
|
||||
:publishing-function z/z-publish-to-html
|
||||
@@ -594,7 +609,7 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
|
||||
("wip-pages"
|
||||
:base-directory ,(site-path "")
|
||||
:publishing-directory ,(site-path "output/")
|
||||
:publishing-directory ,(output-path "")
|
||||
:recursive t
|
||||
:base-extension "org"
|
||||
:publishing-function z/z-publish-to-html
|
||||
@@ -610,7 +625,7 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
|
||||
("org-tags"
|
||||
:base-directory ,(site-path "tags/")
|
||||
:publishing-directory ,(site-path "output/tags/")
|
||||
:publishing-directory ,(output-path "tags/")
|
||||
:recursive t
|
||||
:base-extension "org"
|
||||
:publishing-function org-html-publish-to-html
|
||||
@@ -620,7 +635,7 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
|
||||
("org-lima"
|
||||
:base-directory ,(site-path "lima/")
|
||||
:publishing-directory ,(site-path "output/lima/")
|
||||
:publishing-directory ,(output-path "lima/")
|
||||
:recursive t
|
||||
:base-extension "org\\|md"
|
||||
:publishing-function z/publish-lima-file
|
||||
@@ -650,10 +665,12 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
;; Rule: whenever output/ is deleted, .org-timestamps/ must be deleted too.
|
||||
|
||||
(z/log-separator "Pre-build")
|
||||
(z/log 'info "Site source root : %s" z/site-root)
|
||||
(z/log 'info "Site output root : %s" z/output-root)
|
||||
|
||||
(defun z/wipe-build-dirs ()
|
||||
"Delete output/, tags/, and .org-timestamps/ together."
|
||||
(dolist (dir (list (site-path "output/")
|
||||
(dolist (dir (list z/output-root
|
||||
(site-path "tags/")
|
||||
(site-path ".org-timestamps/")))
|
||||
(if (file-directory-p dir)
|
||||
@@ -670,10 +687,10 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
Returns nil (and logs warnings) if assets/ or any top-level HTML is missing.
|
||||
A nil result means the timestamp cache is stale and we must force-republish."
|
||||
(let ((missing '()))
|
||||
(unless (file-directory-p (site-path "output/assets/"))
|
||||
(unless (file-directory-p (output-path "assets/"))
|
||||
(push "output/assets/" missing))
|
||||
(unless (or (file-exists-p (site-path "output/index.html"))
|
||||
(file-exists-p (site-path "output/sitemap.html")))
|
||||
(unless (or (file-exists-p (output-path "index.html"))
|
||||
(file-exists-p (output-path "sitemap.html")))
|
||||
(push "output/index.html (or sitemap.html)" missing))
|
||||
(dolist (m missing)
|
||||
(z/log 'warn "Integrity check: missing %s" m))
|
||||
@@ -745,14 +762,14 @@ A nil result means the timestamp cache is stale and we must force-republish."
|
||||
(z/log-separator "Build summary")
|
||||
|
||||
(let* ((elapsed (- (float-time) z/build-start-time))
|
||||
(out-dir (site-path "output/"))
|
||||
(out-dir z/output-root)
|
||||
(html-files (when (file-directory-p out-dir)
|
||||
(length (directory-files-recursively out-dir "\\.html\\'"))))
|
||||
(css-files (when (file-directory-p out-dir)
|
||||
(length (directory-files-recursively out-dir "\\.css\\'"))))
|
||||
(js-files (when (file-directory-p out-dir)
|
||||
(length (directory-files-recursively out-dir "\\.js\\'"))))
|
||||
(tag-files (let ((td (site-path "output/tags/")))
|
||||
(tag-files (let ((td (output-path "tags/")))
|
||||
(when (file-directory-p td)
|
||||
(length (directory-files td nil "\\.html\\'"))))))
|
||||
(z/log 'metric "Total elapsed : %.2fs" elapsed)
|
||||
|
||||
Reference in New Issue
Block a user