;;; build-assets.el --- Asset URLs and publishing helpers -*- lexical-binding: t; -*- ;;; Code: (defun z/asset-version (path) "Return a cache-busting version string for asset PATH under `z/site-root'." (let* ((file (site-path path)) (attrs (and (file-exists-p file) (file-attributes file))) (mtime (and attrs (file-attribute-modification-time attrs))) (size (and attrs (file-attribute-size attrs)))) (if (and mtime size) (format "%x-%x" (floor (float-time mtime)) size) (format "%x" (floor z/build-start-time))))) (defun z/asset-url (path) "Return root-relative asset PATH with a deterministic cache-busting query." (format "/%s?v=%s" path (z/asset-version path))) (defvar z/shared-head (concat "\n" (mapconcat (lambda (f) (format "" (z/asset-url (format "assets/styles/%s" f)))) '("style.css" "bigger-picture.min.css" "comments.css" "kanban.css" "org-syntax.css" "misc.css" "media.css" "wird-tracker.css" "zhd.css" "play.css" "hidden-details.css") "\n") "\n" (mapconcat (lambda (f) (format "" (z/asset-url (format "assets/scripts/%s" f)))) '("script.js" "lunr.js" "competency-status-board.js" "notes.js" "comments.js" "bigger-picture.min.js" "search.js" "svg-pan-zoom.min.js" "gallery-init.js" "sitemap-interactive.js" "wird-tracker.js" "zhd.js" "play.js" "ash-below-lake.js" "hidden-details.js") "\n") (format "" (z/asset-url "assets/scripts/mermaid.min.js"))) "Shared HTML fragment injected into every page.") (defun z/sync-assets-to-output () "Copy assets/ into the configured output assets directory, overwriting stale files." (let ((source-root (site-path "assets/")) (target-root (output-path "assets/"))) (when (file-directory-p source-root) (dolist (file (directory-files-recursively source-root ".*" nil)) (unless (file-directory-p file) (let* ((rel (file-relative-name file source-root)) (target (expand-file-name rel target-root))) (make-directory (file-name-directory target) t) (copy-file file target t t t t))))))) (provide 'build-assets) ;;; build-assets.el ends here