;;; 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)))) '("ui/copy-buttons.js" "ui/footnote-sidenotes.js" "application/theme-switcher.js" "ui/countdown.js" "ui/toc-active-link.js" "ui/mermaid-diagrams.js" "vendor/lunr.js" "pages/competency-status-board.js" "pages/notes.js" "features/comments.js" "vendor/bigger-picture.min.js" "search.js" "vendor/svg-pan-zoom.min.js" "ui/gallery-init.js" "pages/sitemap-interactive.js" "pages/wird-tracker.js" "pages/home-dashboard.js" "pages/play.js" "pages/ash-below-lake.js" "features/hidden-details.js") "\n") (format "" (z/asset-url "assets/scripts/vendor/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