seperating build
This commit is contained in:
78
lisp/build-assets.el
Normal file
78
lisp/build-assets.el
Normal file
@@ -0,0 +1,78 @@
|
||||
;;; 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
|
||||
"<link rel=\"icon\" type=\"image/png\" sizes=\"48x48\""
|
||||
" href=\"/assets/icons/icons8-film-tape-100.png\" />\n"
|
||||
(mapconcat
|
||||
(lambda (f)
|
||||
(format "<link rel=\"stylesheet\" href=\"%s\" />"
|
||||
(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 "<script src=\"%s\" defer></script>"
|
||||
(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 "<script src=\"%s\"></script>"
|
||||
(z/asset-url "assets/scripts/mermaid.min.js")))
|
||||
"Shared <head> 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
|
||||
103
lisp/build-comments.el
Normal file
103
lisp/build-comments.el
Normal file
@@ -0,0 +1,103 @@
|
||||
;;; build-comments.el --- Comment manifest and export filter -*- lexical-binding: t; -*-
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'cl-lib)
|
||||
(require 'json)
|
||||
(require 'org)
|
||||
|
||||
(defun z/comments-file-p (file)
|
||||
"Return non-nil if FILE has #+COMMENTS: t."
|
||||
(when (and file (file-exists-p file))
|
||||
(with-temp-buffer
|
||||
(insert-file-contents file)
|
||||
(org-mode)
|
||||
(let* ((keywords (org-collect-keywords '("COMMENTS")))
|
||||
(val (cadr (assoc "COMMENTS" keywords))))
|
||||
(and val
|
||||
(string-match-p "^\\s-*t\\s-*$" (downcase val)))))))
|
||||
|
||||
(defun z/comments-file-slug (file)
|
||||
"Return page slug from #+SLUG: or fallback to filename base."
|
||||
(with-temp-buffer
|
||||
(insert-file-contents file)
|
||||
(org-mode)
|
||||
(let* ((keywords (org-collect-keywords '("SLUG")))
|
||||
(slug (cadr (assoc "SLUG" keywords))))
|
||||
(if (and slug (string-match-p "\\S-" slug))
|
||||
slug
|
||||
(file-name-base file)))))
|
||||
|
||||
(defun z/comment-page-url (file)
|
||||
"Return root-relative published HTML URL for source FILE."
|
||||
(concat "/"
|
||||
(file-name-sans-extension
|
||||
(file-relative-name file z/site-root))
|
||||
".html"))
|
||||
|
||||
(defun z/comment-page-title (file)
|
||||
"Return exported page title for FILE, or the file basename."
|
||||
(with-temp-buffer
|
||||
(insert-file-contents file nil 0 4096)
|
||||
(goto-char (point-min))
|
||||
(if (re-search-forward "^#\\+TITLE:[ \t]*\\(.+?\\)[ \t]*$" nil t)
|
||||
(match-string 1)
|
||||
(file-name-base file))))
|
||||
|
||||
(defun z/comment-page-record (file)
|
||||
"Return a JSON-ready comment page record for FILE."
|
||||
`((slug . ,(z/comments-file-slug file))
|
||||
(title . ,(z/comment-page-title file))
|
||||
(url . ,(z/comment-page-url file))))
|
||||
|
||||
(defun z/generate-comment-pages-json ()
|
||||
"Write a slug-to-page manifest for comment-enabled Org files."
|
||||
(let* ((files (directory-files-recursively z/site-root "\\.org\\'"))
|
||||
(records
|
||||
(cl-loop for file in files
|
||||
unless (or (string-prefix-p (site-path "output/") file)
|
||||
(string-prefix-p (site-path "backups/") file)
|
||||
(string-prefix-p (site-path ".org-timestamps/") file)
|
||||
(string-prefix-p (site-path ".packages/") file))
|
||||
when (z/comments-file-p file)
|
||||
collect (z/comment-page-record file)))
|
||||
(target (site-path "assets/content/comment-pages.json"))
|
||||
(json-encoding-pretty-print t))
|
||||
(make-directory (file-name-directory target) t)
|
||||
(with-temp-file target
|
||||
(insert (json-encode (vconcat records)))
|
||||
(insert "\n"))
|
||||
(z/log 'done "Wrote comment page manifest (%d pages)" (length records))))
|
||||
|
||||
(defun z/org-html-insert-comments-into-body (body backend info)
|
||||
"Append a comments section to BODY for files that opt in."
|
||||
(if (org-export-derived-backend-p backend 'html)
|
||||
(let ((input-file (plist-get info :input-file)))
|
||||
(if (and input-file (z/comments-file-p input-file))
|
||||
(let* ((slug (z/comments-file-slug input-file))
|
||||
(html (format
|
||||
"\n<section id=\"comments\" class=\"comments\" data-slug=\"%s\">
|
||||
<h2>Comments</h2>
|
||||
<div id=\"comments-list\" class=\"comments-list\">
|
||||
<noscript>Please enable JavaScript to view comments.</noscript>
|
||||
</div>
|
||||
<form id=\"comment-form\" class=\"comment-form\">
|
||||
<label class=\"comment-author\">
|
||||
<span>Name (optional)</span>
|
||||
<input type=\"text\" name=\"author\"/>
|
||||
</label>
|
||||
<label class=\"comment-content\">
|
||||
<span>Your comment</span>
|
||||
<textarea name=\"content\" required></textarea>
|
||||
</label>
|
||||
<button type=\"submit\">Post comment</button>
|
||||
</form>
|
||||
</section>\n"
|
||||
slug)))
|
||||
(concat body html))
|
||||
body))
|
||||
body))
|
||||
|
||||
(provide 'build-comments)
|
||||
|
||||
;;; build-comments.el ends here
|
||||
102
lisp/build-core.el
Normal file
102
lisp/build-core.el
Normal file
@@ -0,0 +1,102 @@
|
||||
;;; build-core.el --- Build bootstrap and logging -*- lexical-binding: t; -*-
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'package)
|
||||
|
||||
(defconst z/colour-reset "\033[0m")
|
||||
(defconst z/colour-bold "\033[1m")
|
||||
(defconst z/colour-dim "\033[2m")
|
||||
(defconst z/colour-green "\033[32m")
|
||||
(defconst z/colour-yellow "\033[33m")
|
||||
(defconst z/colour-cyan "\033[36m")
|
||||
(defconst z/colour-red "\033[31m")
|
||||
(defconst z/colour-blue "\033[34m")
|
||||
(defconst z/colour-magenta "\033[35m")
|
||||
|
||||
(defun z/log (level fmt &rest args)
|
||||
"Emit a coloured build-log line.
|
||||
LEVEL is one of: info warn error step metric done.
|
||||
FMT and ARGS are passed to `format'."
|
||||
(let* ((msg (apply #'format fmt args))
|
||||
(prefix
|
||||
(pcase level
|
||||
('info (concat z/colour-cyan " INFO " z/colour-reset))
|
||||
('warn (concat z/colour-yellow " WARN " z/colour-reset))
|
||||
('error (concat z/colour-red " ERROR " z/colour-reset))
|
||||
('step (concat z/colour-blue z/colour-bold " ---- " z/colour-reset))
|
||||
('metric (concat z/colour-magenta " * " z/colour-reset))
|
||||
('done (concat z/colour-green z/colour-bold " OK " z/colour-reset))
|
||||
(_ " "))))
|
||||
(message "%s%s" prefix msg)))
|
||||
|
||||
(defun z/log-separator (&optional label)
|
||||
"Print a separator line, optionally with LABEL."
|
||||
(if label
|
||||
(message "%s%s-- %s %s%s"
|
||||
z/colour-dim z/colour-bold label
|
||||
(make-string (max 0 (- 60 (length label))) ?-)
|
||||
z/colour-reset)
|
||||
(message "%s%s%s"
|
||||
z/colour-dim
|
||||
(make-string 66 ?-)
|
||||
z/colour-reset)))
|
||||
|
||||
(defmacro z/with-timing (label &rest body)
|
||||
"Execute BODY, then log elapsed seconds under LABEL."
|
||||
(declare (indent 1))
|
||||
(let ((t0 (gensym "t0")))
|
||||
`(let ((,t0 (float-time)))
|
||||
(prog1 (progn ,@body)
|
||||
(z/log 'metric "%s took %.2fs" ,label (- (float-time) ,t0))))))
|
||||
|
||||
(defun z/bootstrap-packages ()
|
||||
"Set up Emacs packages required by the build."
|
||||
(z/log-separator "Package setup")
|
||||
(setq package-user-dir (site-path ".packages"))
|
||||
(setq package-archives
|
||||
'(("melpa" . "https://melpa.org/packages/")
|
||||
("elpa" . "https://elpa.gnu.org/packages/")))
|
||||
(package-initialize)
|
||||
(z/with-timing "Package archive refresh"
|
||||
(unless package-archive-contents
|
||||
(z/log 'info "Refreshing package archive contents...")
|
||||
(condition-case err
|
||||
(package-refresh-contents)
|
||||
(error
|
||||
(z/log 'warn "Could not refresh archives: %s" (error-message-string err))))))
|
||||
(z/with-timing "htmlize install"
|
||||
(unless (package-installed-p 'htmlize)
|
||||
(z/log 'info "Installing htmlize...")
|
||||
(condition-case err
|
||||
(package-install 'htmlize)
|
||||
(error
|
||||
(z/log 'error "htmlize install failed: %s" (error-message-string err))
|
||||
(error "Cannot continue without htmlize")))))
|
||||
(require 'htmlize))
|
||||
|
||||
(defun z/configure-org ()
|
||||
"Load Org export libraries and configure shared Org settings."
|
||||
(require 'ox-publish)
|
||||
(require 'cl-lib)
|
||||
(require 'json)
|
||||
(require 'org)
|
||||
(require 'ox)
|
||||
(require 'ox-html)
|
||||
(require 'ox-md)
|
||||
(setq org-publish-timestamp-directory (site-path ".org-timestamps/"))
|
||||
(setq org-html-htmlize-output-type 'css))
|
||||
|
||||
(defun z/require-local (library)
|
||||
"Require local build LIBRARY with consistent error reporting."
|
||||
(condition-case err
|
||||
(progn
|
||||
(require library)
|
||||
(z/log 'done "Loaded %s" library))
|
||||
(error
|
||||
(z/log 'error "Failed to load %s: %s" library (error-message-string err))
|
||||
(error "Aborting: required library %s missing" library))))
|
||||
|
||||
(provide 'build-core)
|
||||
|
||||
;;; build-core.el ends here
|
||||
113
lisp/build-html.el
Normal file
113
lisp/build-html.el
Normal file
@@ -0,0 +1,113 @@
|
||||
;;; build-html.el --- HTML export customisation -*- lexical-binding: t; -*-
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'org)
|
||||
(require 'ox-html)
|
||||
(require 'subr-x)
|
||||
(require 'tags)
|
||||
(require 'sidenotes)
|
||||
(require 'build-comments)
|
||||
|
||||
(setq org-export-global-macros
|
||||
(append
|
||||
org-export-global-macros
|
||||
'(("sidenote"
|
||||
. "@@html:<label for=\"sn$1\" class=\"margin-toggle sidenote-number\"></label>\
|
||||
<input type=\"checkbox\" id=\"sn$1\" class=\"margin-toggle\"/>\
|
||||
<span class=\"sidenote\">$2</span>@@")
|
||||
("epigraph"
|
||||
. "@@html:<div class=\"epigraph\"><blockquote>$1<footer>$2</footer></blockquote></div>@@")
|
||||
("epigraph_single"
|
||||
. "@@html:<div class=\"epigraph\"><blockquote>$1</blockquote></div>@@")
|
||||
("epigraph3"
|
||||
. "@@html:<div class=\"epigraph\"><blockquote>$1<footer>$2, <cite>$3</cite></footer></blockquote></div>@@")
|
||||
("kbd"
|
||||
. "@@html:<kbd>$1</kbd>@@@@latex:\\texttt{$1}@@")
|
||||
("margimg"
|
||||
. "@@html:<aside class=\"marginnote\"><figure class=\"mn-fig\">\
|
||||
<img src=\"$1\" alt=\"$2\" class=\"mn-img\" loading=\"lazy\" decoding=\"async\"/>$3\
|
||||
</figure></aside>@@")
|
||||
("countdown"
|
||||
. "@@html:<time class=\"countdown\" datetime=\"$1\" data-label=\"$2\"></time>@@"))))
|
||||
|
||||
(defvar z/preamble
|
||||
"<div class=\"banner-header\" role=\"banner\">
|
||||
<a class=\"site-brand\" href=\"/\" aria-label=\"Home\">
|
||||
<img src=\"/assets/images/gr.png\" alt=\"\" class=\"banner-logo\" />
|
||||
<span class=\"site-brand__text\">zxh</span>
|
||||
</a>
|
||||
<nav class=\"site-nav\" aria-label=\"Primary\">
|
||||
<a href=\"/\">Home</a>
|
||||
<a href=\"/blogs/blogs-list.html\">Blogs</a>
|
||||
<a href=\"/posts/career/career-list.html\">Career</a>
|
||||
<a href=\"/play.html\">Play</a>
|
||||
<a href=\"https://zone.zainezq.com\">Dashboard</a>
|
||||
</nav>
|
||||
<div class=\"site-actions\">
|
||||
<label class=\"site-search\" for=\"search-input\">
|
||||
<span class=\"visually-hidden\">Search notes</span>
|
||||
<input type=\"search\" id=\"search-input\" placeholder=\"Search notes\" aria-label=\"Search notes\" />
|
||||
</label>
|
||||
<button id=\"search-btn\" aria-label=\"Search\" type=\"button\">Search</button>
|
||||
<button class=\"theme-toggle\" id=\"theme-toggle\" type=\"button\" aria-label=\"Switch theme\">Theme</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id=\"updated\">Updated: %C</div>
|
||||
")
|
||||
|
||||
(defvar z/postamble
|
||||
"<footer>
|
||||
<div class=\"copyright-container\">
|
||||
<div class=\"copyright\">
|
||||
Copyright © 2022-2026 Zaine Qayyum. All rights reserved unless otherwise noted.</div></div>
|
||||
<div class=\"generated\">
|
||||
Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> \
|
||||
<a href=\"https://www.gnu.org\">GNU</a>/<a href=\"https://www.kernel.org/\">Linux</a>
|
||||
</div>
|
||||
</footer>")
|
||||
|
||||
(defun z/org-html-src-block-mermaid (orig-fun src-block contents info)
|
||||
"Export Mermaid source blocks as Mermaid divs."
|
||||
(let ((lang (org-element-property :language src-block)))
|
||||
(if (string= lang "mermaid")
|
||||
(let ((code (org-remove-indentation
|
||||
(org-element-property :value src-block))))
|
||||
(format "<div class=\"mermaid\">\n%s\n</div>" code))
|
||||
(funcall orig-fun src-block contents info))))
|
||||
|
||||
(advice-add 'org-html-src-block :around #'z/org-html-src-block-mermaid)
|
||||
|
||||
(defun z/org-html-add-body-classes (output backend info)
|
||||
"Add layout-related classes to <body> based on file metadata."
|
||||
(if (org-export-derived-backend-p backend 'html)
|
||||
(let* ((input-file (plist-get info :input-file))
|
||||
(classes
|
||||
(delq nil
|
||||
(list
|
||||
(when (and input-file (z/no-sidenotes-file-p input-file))
|
||||
"no-sidenotes")))))
|
||||
(if classes
|
||||
(replace-regexp-in-string
|
||||
"<body\\([^>]*\\)>"
|
||||
(format "<body\\1 class=\"%s\">"
|
||||
(string-join classes " "))
|
||||
output)
|
||||
output))
|
||||
output))
|
||||
|
||||
(add-to-list 'org-export-filter-final-output-functions
|
||||
#'z/org-html-add-body-classes)
|
||||
(add-to-list 'org-export-filter-body-functions
|
||||
#'z/org-html-insert-comments-into-body)
|
||||
|
||||
(org-export-define-derived-backend 'z-html 'html
|
||||
:filters-alist '((:filter-final-output . z/insert-filetags-after-title)))
|
||||
|
||||
(defun z/z-publish-to-html (plist filename pub-dir)
|
||||
"Publish FILENAME to HTML using the z-html backend."
|
||||
(org-publish-org-to 'z-html filename ".html" plist pub-dir))
|
||||
|
||||
(provide 'build-html)
|
||||
|
||||
;;; build-html.el ends here
|
||||
89
lisp/build-lima.el
Normal file
89
lisp/build-lima.el
Normal file
@@ -0,0 +1,89 @@
|
||||
;;; build-lima.el --- Lima publishing adapter -*- lexical-binding: t; -*-
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'org)
|
||||
(require 'ox-publish)
|
||||
|
||||
(defun z/lima-entry-title (file fallback)
|
||||
"Return FILE's Org title, or FALLBACK when no title is present."
|
||||
(with-temp-buffer
|
||||
(insert-file-contents file nil 0 4096)
|
||||
(goto-char (point-min))
|
||||
(if (re-search-forward "^#\\+TITLE:[ \t]*\\(.+?\\)[ \t]*$" nil t)
|
||||
(match-string 1)
|
||||
fallback)))
|
||||
|
||||
(defun z/lima-sitemap-format-entry (entry _style project)
|
||||
"Format a sitemap ENTRY for Lima; skip directories."
|
||||
(let* ((file (if (listp entry) (car entry) entry))
|
||||
(base-dir (file-name-as-directory
|
||||
(org-publish-property :base-directory project)))
|
||||
(abs (if (file-name-absolute-p file)
|
||||
file
|
||||
(expand-file-name file base-dir))))
|
||||
(unless (file-directory-p abs)
|
||||
(let* ((rel (file-relative-name abs base-dir))
|
||||
(rel-noext (file-name-sans-extension rel))
|
||||
(title (z/lima-entry-title abs (file-name-nondirectory rel-noext))))
|
||||
(format "[[file:%s.html][%s]]"
|
||||
rel-noext
|
||||
title)))))
|
||||
|
||||
(defun z/copy-neighbor-attachments (source-dir pub-dir)
|
||||
"Copy sibling .attachments.* directories from SOURCE-DIR into PUB-DIR."
|
||||
(dolist (d (directory-files source-dir t "^\\.attachments\\..+"))
|
||||
(when (file-directory-p d)
|
||||
(let ((target (expand-file-name (file-name-nondirectory d) pub-dir)))
|
||||
(make-directory target t)
|
||||
(copy-directory d target t t t)))))
|
||||
|
||||
(defun z/markdown-h1-title (filename fallback)
|
||||
"Return the first Markdown H1 title in FILENAME, or FALLBACK."
|
||||
(with-temp-buffer
|
||||
(insert-file-contents filename nil 0 4096)
|
||||
(goto-char (point-min))
|
||||
(if (re-search-forward "^#+ +\\(.+?\\)\\s-*$" nil t)
|
||||
(match-string 1)
|
||||
fallback)))
|
||||
|
||||
(defun z/publish-lima-file (plist filename pub-dir)
|
||||
"Publish an Org or Markdown file from the lima directory."
|
||||
(let* ((ext (downcase (or (file-name-extension filename) "")))
|
||||
(base (file-name-base filename))
|
||||
(src-dir (file-name-directory filename)))
|
||||
(cond
|
||||
((string= ext "org")
|
||||
(z/copy-neighbor-attachments src-dir pub-dir)
|
||||
(org-publish-org-to 'z-html filename ".html" plist pub-dir))
|
||||
((string= ext "md")
|
||||
(let* ((tmp-dir (make-temp-file "lima-build-" t))
|
||||
(temp-org (expand-file-name (concat base ".org") tmp-dir)))
|
||||
(let ((rc (call-process "pandoc" nil nil nil
|
||||
filename "-f" "markdown" "-t" "org" "-o" temp-org)))
|
||||
(unless (zerop rc)
|
||||
(z/log 'error "pandoc failed (rc=%d) for %s" rc filename)
|
||||
(error "pandoc conversion failed for %s" filename)))
|
||||
(with-temp-buffer
|
||||
(insert-file-contents temp-org)
|
||||
(goto-char (point-min))
|
||||
(insert (format "#+TITLE: %s\n#+OPTIONS: num:nil\n#+DATE: %s\n#+COMMENTS: t\n#+SLUG: %s\n\n"
|
||||
(z/markdown-h1-title filename base)
|
||||
(format-time-string "<%Y-%m-%d %a %H:%M>")
|
||||
base))
|
||||
(write-region (point-min) (point-max) temp-org))
|
||||
(z/copy-neighbor-attachments src-dir pub-dir)
|
||||
(let ((output-file (expand-file-name (concat base ".html") pub-dir)))
|
||||
(org-publish-org-to 'z-html temp-org ".html" plist pub-dir)
|
||||
(let ((generated (expand-file-name
|
||||
(concat (file-name-base temp-org) ".html")
|
||||
pub-dir)))
|
||||
(when (and (file-exists-p generated)
|
||||
(not (string-equal generated output-file)))
|
||||
(rename-file generated output-file t))))))
|
||||
(t
|
||||
(org-publish-attachment plist filename pub-dir)))))
|
||||
|
||||
(provide 'build-lima)
|
||||
|
||||
;;; build-lima.el ends here
|
||||
139
lisp/build-projects.el
Normal file
139
lisp/build-projects.el
Normal file
@@ -0,0 +1,139 @@
|
||||
;;; build-projects.el --- org-publish project configuration -*- lexical-binding: t; -*-
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'ox-publish)
|
||||
|
||||
(defun z/org-main-prep (_project)
|
||||
"Pre-publish hook: regenerate recently-updated.org."
|
||||
(z/log 'step "Generating recently-updated.org...")
|
||||
(z/with-timing "recently-updated generation"
|
||||
(z/generate-recently-updated-org 26)))
|
||||
|
||||
(defun z/configure-publish-projects ()
|
||||
"Install `org-publish-project-alist' for the site."
|
||||
(setq org-publish-project-alist
|
||||
`(("org-main"
|
||||
:recursive t
|
||||
:base-directory ,(site-path "")
|
||||
:publishing-function z/z-publish-to-html
|
||||
:publishing-directory ,(output-path "")
|
||||
:base-extension "org"
|
||||
:auto-sitemap t
|
||||
:sitemap-filename "sitemap.org"
|
||||
:sitemap-title "Sitemap"
|
||||
:sitemap-function z/main-sitemap
|
||||
:sitemap-sort-files chronologically
|
||||
:html-preamble ,z/preamble
|
||||
:html-postamble ,z/postamble
|
||||
:html-head ,z/shared-head
|
||||
:preparation-function z/org-main-prep)
|
||||
|
||||
("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 ,(output-path "assets/")
|
||||
:recursive t
|
||||
:publishing-function org-publish-attachment)
|
||||
|
||||
("org-categories-sitemap"
|
||||
:recursive t
|
||||
:base-directory ,(site-path "home/")
|
||||
:publishing-directory ,(output-path "home/")
|
||||
:base-extension "org"
|
||||
:auto-sitemap t
|
||||
:sitemap-filename "categories.org"
|
||||
:sitemap-title "Categories"
|
||||
:sitemap-function z/categories-sitemap
|
||||
:html-preamble ,z/preamble
|
||||
:html-postamble ,z/postamble
|
||||
:html-head ,z/shared-head)
|
||||
|
||||
("org-posts"
|
||||
:base-directory ,(site-path "posts/")
|
||||
:publishing-directory ,(output-path "posts/")
|
||||
:recursive t
|
||||
:base-extension "org"
|
||||
:publishing-function z/z-publish-to-html
|
||||
:with-author nil
|
||||
:with-creator nil
|
||||
:html-validation-link nil
|
||||
:with-toc t
|
||||
:section-numbers t
|
||||
:html-preamble ,z/preamble
|
||||
:html-postamble ,z/postamble
|
||||
:auto-sitemap t
|
||||
:sitemap-filename "posts-list.org"
|
||||
:sitemap-title "Posts List"
|
||||
:sitemap-style list
|
||||
:sitemap-function z/posts-sitemap
|
||||
:sitemap-sort-files anti-chronologically
|
||||
:html-head ,z/shared-head)
|
||||
|
||||
("org-blogs"
|
||||
:base-directory ,(site-path "blogs/")
|
||||
:publishing-directory ,(output-path "blogs/")
|
||||
:recursive t
|
||||
:base-extension "org"
|
||||
:publishing-function z/z-publish-to-html
|
||||
:with-author nil
|
||||
:with-creator nil
|
||||
:html-validation-link nil
|
||||
:html-preamble ,z/preamble
|
||||
:html-postamble ,z/postamble
|
||||
:auto-sitemap t
|
||||
:sitemap-filename "blogs-list.org"
|
||||
:sitemap-title "Blogs List"
|
||||
:sitemap-style list
|
||||
:sitemap-function z/blogs-grouped-sitemap
|
||||
:sitemap-sort-files anti-chronologically
|
||||
:html-head ,z/shared-head)
|
||||
|
||||
("org-career"
|
||||
:base-directory ,(site-path "posts/career/")
|
||||
:publishing-directory ,(output-path "posts/career/")
|
||||
:recursive t
|
||||
:base-extension "org"
|
||||
:publishing-function z/z-publish-to-html
|
||||
:html-preamble ,z/preamble
|
||||
:html-postamble ,z/postamble
|
||||
:auto-sitemap t
|
||||
:sitemap-filename "career-list.org"
|
||||
:sitemap-title "Career List"
|
||||
:sitemap-style list
|
||||
:sitemap-function z/career-sitemap
|
||||
:sitemap-sort-files anti-chronologically
|
||||
:html-head ,z/shared-head)
|
||||
|
||||
("org-tags"
|
||||
:base-directory ,(site-path "tags/")
|
||||
:publishing-directory ,(output-path "tags/")
|
||||
:recursive t
|
||||
:base-extension "org"
|
||||
:publishing-function org-html-publish-to-html
|
||||
:html-preamble ,z/preamble
|
||||
:html-postamble ,z/postamble
|
||||
:html-head ,z/shared-head)
|
||||
|
||||
("org-lima"
|
||||
:base-directory ,(site-path "lima/")
|
||||
:publishing-directory ,(output-path "lima/")
|
||||
:recursive t
|
||||
:base-extension "org\\|md"
|
||||
:publishing-function z/publish-lima-file
|
||||
:with-author nil
|
||||
:with-creator nil
|
||||
:html-validation-link nil
|
||||
:html-preamble ,z/preamble
|
||||
:html-postamble ,z/postamble
|
||||
:sitemap-filename "lima-list.org"
|
||||
:auto-sitemap t
|
||||
:sitemap-title "Lima"
|
||||
:sitemap-style list
|
||||
:sitemap-sort-files anti-chronologically
|
||||
:sitemap-format-entry z/lima-sitemap-format-entry
|
||||
:html-head ,z/shared-head))))
|
||||
|
||||
(provide 'build-projects)
|
||||
|
||||
;;; build-projects.el ends here
|
||||
120
lisp/build-runner.el
Normal file
120
lisp/build-runner.el
Normal file
@@ -0,0 +1,120 @@
|
||||
;;; build-runner.el --- Build orchestration -*- lexical-binding: t; -*-
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'ox-publish)
|
||||
|
||||
(defun z/wipe-build-dirs ()
|
||||
"Delete output/ and .org-timestamps/ together."
|
||||
(dolist (dir (list z/output-root
|
||||
(site-path ".org-timestamps/")))
|
||||
(if (file-directory-p dir)
|
||||
(progn
|
||||
(z/with-timing (format "delete %s"
|
||||
(file-name-nondirectory
|
||||
(directory-file-name dir)))
|
||||
(delete-directory dir t))
|
||||
(z/log 'done "Deleted %s" dir))
|
||||
(z/log 'info "Already absent: %s" dir))))
|
||||
|
||||
(defun z/output-integrity-ok-p ()
|
||||
"Return t if critical output paths all exist."
|
||||
(let ((missing '()))
|
||||
(unless (file-directory-p (output-path "assets/"))
|
||||
(push "output/assets/" missing))
|
||||
(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))
|
||||
(null missing)))
|
||||
|
||||
(defun z/prepare-output-cache ()
|
||||
"Keep org-publish output and timestamp cache in sync."
|
||||
(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)
|
||||
(cond
|
||||
((getenv "SITE_CLEAN")
|
||||
(z/log 'warn "SITE_CLEAN=1 - wiping output/ and .org-timestamps/")
|
||||
(z/wipe-build-dirs)
|
||||
(setenv "SITE_FORCE" "1"))
|
||||
((not (z/output-integrity-ok-p))
|
||||
(z/log 'warn "Output integrity check failed - timestamp cache is stale")
|
||||
(z/log 'warn "Clearing .org-timestamps/ and forcing full republish")
|
||||
(let ((ts-dir (site-path ".org-timestamps/")))
|
||||
(when (file-directory-p ts-dir)
|
||||
(z/with-timing "delete .org-timestamps"
|
||||
(delete-directory ts-dir t))
|
||||
(z/log 'done "Deleted .org-timestamps/")))
|
||||
(setenv "SITE_FORCE" "1"))
|
||||
(t
|
||||
(z/log 'info "Incremental build - output/ looks complete"))))
|
||||
|
||||
(defun z/generate-build-inputs ()
|
||||
"Generate source-side data files required before publishing."
|
||||
(z/log-separator "Generated inputs")
|
||||
(z/with-timing "tag page generation"
|
||||
(condition-case err
|
||||
(let ((n (z/write-tag-pages)))
|
||||
(z/log 'done "Tag pages written%s"
|
||||
(if (numberp n) (format " (%d tags)" n) "")))
|
||||
(error
|
||||
(z/log 'error "Tag generation failed: %s" (error-message-string err))
|
||||
(error "Aborting build: tag generation error"))))
|
||||
(z/with-timing "comment page manifest"
|
||||
(condition-case err
|
||||
(z/generate-comment-pages-json)
|
||||
(error
|
||||
(z/log 'error "Comment page manifest failed: %s" (error-message-string err))
|
||||
(error "Aborting build: comment page manifest error")))))
|
||||
|
||||
(defun z/publish-site ()
|
||||
"Publish the configured site."
|
||||
(z/log-separator "Publishing")
|
||||
(if (getenv "SITE_DRY")
|
||||
(z/log 'warn "SITE_DRY=1 - skipping org-publish-all (dry run)")
|
||||
(let ((force (not (not (getenv "SITE_FORCE")))))
|
||||
(when force
|
||||
(z/log 'info "SITE_FORCE=1 - forcing republish of all files"))
|
||||
(condition-case err
|
||||
(progn
|
||||
(z/with-timing "org-publish-all"
|
||||
(org-publish-all force))
|
||||
(z/with-timing "asset sync"
|
||||
(z/sync-assets-to-output)))
|
||||
(error
|
||||
(z/log 'error "org-publish-all failed: %s" (error-message-string err))
|
||||
(error "Build failed"))))))
|
||||
|
||||
(defun z/log-build-summary ()
|
||||
"Log a summary of output artifacts."
|
||||
(z/log-separator "Build summary")
|
||||
(let* ((elapsed (- (float-time) z/build-start-time))
|
||||
(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 (output-path "tags/")))
|
||||
(when (file-directory-p td)
|
||||
(length (directory-files td nil "\\.html\\'"))))))
|
||||
(z/log 'metric "Total elapsed : %.2fs" elapsed)
|
||||
(z/log 'metric "HTML files output: %d" (or html-files 0))
|
||||
(z/log 'metric "CSS files output: %d" (or css-files 0))
|
||||
(z/log 'metric "JS files output: %d" (or js-files 0))
|
||||
(z/log 'metric "Tag pages output: %d" (or tag-files 0))
|
||||
(z/log 'done "Build complete")))
|
||||
|
||||
(defun z/run-build ()
|
||||
"Run the full site build."
|
||||
(z/prepare-output-cache)
|
||||
(z/generate-build-inputs)
|
||||
(z/publish-site)
|
||||
(z/log-build-summary))
|
||||
|
||||
(provide 'build-runner)
|
||||
|
||||
;;; build-runner.el ends here
|
||||
@@ -20,8 +20,7 @@
|
||||
(defconst z/recent-omit-names
|
||||
'("sitemap.org"
|
||||
"categories.org"
|
||||
"recently-updated.org"
|
||||
"wip.org")
|
||||
"recently-updated.org")
|
||||
"Org files that are always excluded from the recently-updated list.")
|
||||
|
||||
(defun z/recent-omit-org-p (rel-org)
|
||||
|
||||
@@ -351,59 +351,6 @@ CATEGORIES-REL is the relative href to categories.html."
|
||||
"\n")
|
||||
"_No tags found yet._")))))
|
||||
|
||||
;; ─────────────────────────────────────────────────────────────────────────────
|
||||
;; WIP sitemap
|
||||
;; ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
(defun z/wip-file-p (file)
|
||||
"Return non-nil if FILE is marked as work-in-progress.
|
||||
|
||||
A file is WIP when any of the following is true:
|
||||
- It has a #+WIP: keyword with a non-empty value.
|
||||
- Its FILETAGS contain :WIP:.
|
||||
- Any top-level heading contains \"WIP\" (case-insensitive)."
|
||||
(when (file-exists-p file)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents file)
|
||||
(org-mode)
|
||||
(let* ((case-fold-search t)
|
||||
(keywords (org-collect-keywords '("WIP" "FILETAGS")))
|
||||
(wip (cadr (assoc "WIP" keywords)))
|
||||
(filetags (cadr (assoc "FILETAGS" keywords))))
|
||||
(or
|
||||
(and wip (string-match-p "\\S-" wip))
|
||||
(and filetags (string-match-p ":WIP:" (concat ":" filetags ":")))
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(re-search-forward "^\\*+ .*WIP.*" nil t)))))))
|
||||
|
||||
(defun z/wip-sitemap (title list)
|
||||
"Sitemap listing only entries whose source files are marked WIP."
|
||||
(let ((items
|
||||
(delq nil
|
||||
(mapcar
|
||||
(lambda (entry)
|
||||
(when (consp entry)
|
||||
(let* ((link (car entry))
|
||||
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
|
||||
(match-string 1 link)
|
||||
link))
|
||||
(full-path (expand-file-name filename z/site-root)))
|
||||
(when (z/wip-file-p full-path)
|
||||
(let* ((date (org-publish-find-date full-path org-publish-project-alist))
|
||||
(date-str (if date
|
||||
(format-time-string "%d-%m-%Y %H:%M" date)
|
||||
"")))
|
||||
(format "- %s @@html:<span class=\"post-date\">%s</span>@@"
|
||||
link date-str))))))
|
||||
(cdr list)))))
|
||||
(concat "#+TITLE: " title "\n"
|
||||
"#+OPTIONS: toc:nil num:nil\n\n"
|
||||
"* Work in progress\n"
|
||||
(if items
|
||||
(mapconcat #'identity items "\n")
|
||||
"No items currently marked as WIP.\n"))))
|
||||
|
||||
(provide 'sitemaps)
|
||||
|
||||
;;; sitemaps.el ends here
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
(defconst z/generated-org-names
|
||||
'("posts-list.org" "blogs-list.org" "sitemap.org" "categories.org"
|
||||
"recently-updated.org" "wip.org")
|
||||
"recently-updated.org")
|
||||
"Generated Org files that should never be indexed for tags.")
|
||||
|
||||
(defun z/gather-tag-index ()
|
||||
@@ -112,4 +112,4 @@ Returns the number of tag pages written."
|
||||
|
||||
(provide 'tags)
|
||||
|
||||
;;; tags.el ends here
|
||||
;;; tags.el ends here
|
||||
|
||||
264
lisp/tests/build-site-tests.el
Normal file
264
lisp/tests/build-site-tests.el
Normal file
@@ -0,0 +1,264 @@
|
||||
;;; build-site-tests.el --- ERT unit tests for build modules -*- lexical-binding: t; -*-
|
||||
|
||||
;; Run with:
|
||||
;; emacs -Q --batch -l lisp/tests/build-site-tests.el -f ert-run-tests-batch-and-exit
|
||||
;; Or interactively:
|
||||
;; M-x load-file RET lisp/tests/build-site-tests.el RET
|
||||
;; M-x ert RET t RET
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defconst z/test-root
|
||||
(file-name-directory
|
||||
(directory-file-name
|
||||
(file-name-directory
|
||||
(directory-file-name
|
||||
(file-name-directory (or load-file-name buffer-file-name)))))))
|
||||
|
||||
(defconst z/build-start-time (float-time))
|
||||
(defconst z/site-root (file-name-as-directory z/test-root))
|
||||
(defvaralias 'site-root 'z/site-root)
|
||||
(defconst z/output-root (file-name-as-directory (expand-file-name "output/" z/site-root)))
|
||||
|
||||
(defun site-path (path)
|
||||
"Expand PATH relative to test `z/site-root'."
|
||||
(expand-file-name path z/site-root))
|
||||
|
||||
(defun output-path (path)
|
||||
"Expand PATH relative to test `z/output-root'."
|
||||
(expand-file-name path z/output-root))
|
||||
|
||||
(add-to-list 'load-path (site-path "lisp"))
|
||||
|
||||
(require 'ert)
|
||||
(require 'cl-lib)
|
||||
(require 'org)
|
||||
(require 'build-core)
|
||||
|
||||
(z/configure-org)
|
||||
(require 'recently-updated)
|
||||
(require 'tags)
|
||||
(require 'sidenotes)
|
||||
(require 'sitemaps)
|
||||
(require 'build-assets)
|
||||
(require 'build-comments)
|
||||
(require 'build-html)
|
||||
(require 'build-lima)
|
||||
|
||||
;; ── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
(defmacro with-temp-org-file (content &rest body)
|
||||
"Create a temporary .org file containing CONTENT, run BODY with `temp-file' bound."
|
||||
(declare (indent 1))
|
||||
`(let ((temp-file (make-temp-file "build-site-test-" nil ".org")))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(with-temp-file temp-file (insert ,content))
|
||||
,@body)
|
||||
(delete-file temp-file))))
|
||||
|
||||
;; ── site-path ────────────────────────────────────────────────────────────────
|
||||
|
||||
(ert-deftest test/site-path-expands-relative ()
|
||||
"site-path should expand a relative path against site-root."
|
||||
;; We can't call site-path directly without build-site loaded, so we test
|
||||
;; the same logic inline.
|
||||
(let* ((site-root "/tmp/mysite/")
|
||||
(result (expand-file-name "output" site-root)))
|
||||
(should (string= result "/tmp/mysite/output"))))
|
||||
|
||||
(ert-deftest test/site-path-handles-empty-string ()
|
||||
"site-path with \"\" returns the site-root without a trailing slash.
|
||||
`expand-file-name' normalises the result, dropping the trailing slash."
|
||||
(let* ((site-root "/tmp/mysite/")
|
||||
(result (expand-file-name "" site-root)))
|
||||
;; expand-file-name strips the trailing slash, giving "/tmp/mysite"
|
||||
(should (string= result "/tmp/mysite"))))
|
||||
|
||||
;; ── z/comments-file-p ────────────────────────────────────────────────────────
|
||||
|
||||
(ert-deftest test/comments-file-p-returns-true-for-t ()
|
||||
"Files with #+COMMENTS: t should be detected."
|
||||
(with-temp-org-file "#+TITLE: Test\n#+COMMENTS: t\n\nBody.\n"
|
||||
(should (z/comments-file-p temp-file))))
|
||||
|
||||
(ert-deftest test/comments-file-p-case-insensitive ()
|
||||
"#+COMMENTS: T (uppercase) should still match."
|
||||
(with-temp-org-file "#+TITLE: Test\n#+COMMENTS: T\n\nBody.\n"
|
||||
(should (z/comments-file-p temp-file))))
|
||||
|
||||
(ert-deftest test/comments-file-p-returns-nil-for-false ()
|
||||
"Files with #+COMMENTS: nil should return nil."
|
||||
(with-temp-org-file "#+TITLE: Test\n#+COMMENTS: nil\n\nBody.\n"
|
||||
(should-not (z/comments-file-p temp-file))))
|
||||
|
||||
(ert-deftest test/comments-file-p-returns-nil-when-keyword-absent ()
|
||||
"Files without #+COMMENTS keyword should return nil."
|
||||
(with-temp-org-file "#+TITLE: Test\n\nBody.\n"
|
||||
(should-not (z/comments-file-p temp-file))))
|
||||
|
||||
(ert-deftest test/comments-file-p-returns-nil-for-nonexistent-file ()
|
||||
"Non-existent files should return nil, not signal an error."
|
||||
(should-not (z/comments-file-p "/tmp/does-not-exist-ever.org")))
|
||||
|
||||
(ert-deftest test/comments-file-p-tolerates-whitespace ()
|
||||
"#+COMMENTS: with surrounding spaces around 't' should match."
|
||||
(with-temp-org-file "#+TITLE: Test\n#+COMMENTS: t \n\nBody.\n"
|
||||
(should (z/comments-file-p temp-file))))
|
||||
|
||||
;; ── z/comments-file-slug ─────────────────────────────────────────────────────
|
||||
|
||||
(ert-deftest test/comments-file-slug-uses-slug-keyword ()
|
||||
"Should return the #+SLUG: value when present."
|
||||
(with-temp-org-file "#+TITLE: Test\n#+SLUG: my-cool-post\n\nBody.\n"
|
||||
(should (string= "my-cool-post" (z/comments-file-slug temp-file)))))
|
||||
|
||||
(ert-deftest test/comments-file-slug-falls-back-to-filename ()
|
||||
"Should fall back to the file-name-base when #+SLUG is absent."
|
||||
(with-temp-org-file "#+TITLE: Test\n\nBody.\n"
|
||||
(should (string= (file-name-base temp-file)
|
||||
(z/comments-file-slug temp-file)))))
|
||||
|
||||
(ert-deftest test/comments-file-slug-ignores-blank-slug ()
|
||||
"A #+SLUG: with only whitespace should fall back to filename."
|
||||
(with-temp-org-file "#+TITLE: Test\n#+SLUG: \n\nBody.\n"
|
||||
(should (string= (file-name-base temp-file)
|
||||
(z/comments-file-slug temp-file)))))
|
||||
|
||||
;; ── z/org-html-insert-comments-into-body ─────────────────────────────────────
|
||||
|
||||
(ert-deftest test/insert-comments-adds-section-when-enabled ()
|
||||
"Should append a <section id=\"comments\"> block when comments are on."
|
||||
(with-temp-org-file "#+TITLE: Test\n#+COMMENTS: t\n#+SLUG: my-slug\n\nBody.\n"
|
||||
(let* ((info (list :input-file temp-file))
|
||||
(result (z/org-html-insert-comments-into-body "<div>body</div>" 'html info)))
|
||||
(should (string-match-p "id=\"comments\"" result))
|
||||
(should (string-match-p "data-slug=\"my-slug\"" result))
|
||||
(should (string-match-p "<div>body</div>" result)))))
|
||||
|
||||
(ert-deftest test/insert-comments-leaves-body-unchanged-when-disabled ()
|
||||
"Should return body unchanged when #+COMMENTS is absent."
|
||||
(with-temp-org-file "#+TITLE: Test\n\nBody.\n"
|
||||
(let* ((info (list :input-file temp-file))
|
||||
(result (z/org-html-insert-comments-into-body "<div>body</div>" 'html info)))
|
||||
(should (string= "<div>body</div>" result)))))
|
||||
|
||||
(ert-deftest test/insert-comments-ignores-non-html-backends ()
|
||||
"For non-HTML backends the body should pass through unchanged."
|
||||
(with-temp-org-file "#+TITLE: Test\n#+COMMENTS: t\n\nBody.\n"
|
||||
(let* ((info (list :input-file temp-file))
|
||||
(result (z/org-html-insert-comments-into-body "<div>body</div>" 'latex info)))
|
||||
(should (string= "<div>body</div>" result)))))
|
||||
|
||||
(ert-deftest test/insert-comments-handles-nil-input-file ()
|
||||
"Should return body unchanged when :input-file is nil."
|
||||
(let* ((info (list :input-file nil))
|
||||
(result (z/org-html-insert-comments-into-body "<div>body</div>" 'html info)))
|
||||
(should (string= "<div>body</div>" result))))
|
||||
|
||||
(ert-deftest test/insert-comments-slug-from-filename-when-no-slug-keyword ()
|
||||
"Comments section data-slug should fall back to filename when #+SLUG absent."
|
||||
(with-temp-org-file "#+TITLE: Test\n#+COMMENTS: t\n\nBody.\n"
|
||||
(let* ((expected-slug (file-name-base temp-file))
|
||||
(info (list :input-file temp-file))
|
||||
(result (z/org-html-insert-comments-into-body "<div>body</div>" 'html info)))
|
||||
(should (string-match-p (regexp-quote (format "data-slug=\"%s\"" expected-slug))
|
||||
result)))))
|
||||
|
||||
;; ── z/lima-sitemap-format-entry ───────────────────────────────────────────────
|
||||
|
||||
(ert-deftest test/lima-sitemap-format-entry-skips-directories ()
|
||||
"Directories should return nil."
|
||||
(let* ((base-dir (make-temp-file "lima-test-" t))
|
||||
(project (list "lima" :base-directory base-dir)))
|
||||
(unwind-protect
|
||||
(should-not (z/lima-sitemap-format-entry base-dir nil project))
|
||||
(delete-directory base-dir t))))
|
||||
|
||||
(ert-deftest test/lima-sitemap-format-entry-formats-org-file ()
|
||||
"Org files should produce a [[file:...][Title]] link."
|
||||
(let* ((base-dir (make-temp-file "lima-test-" t))
|
||||
(org-file (expand-file-name "my-note.org" base-dir))
|
||||
(project (list "lima" :base-directory base-dir)))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(with-temp-file org-file
|
||||
(insert "#+TITLE: My Note\n\nContent.\n"))
|
||||
(let ((result (z/lima-sitemap-format-entry org-file nil project)))
|
||||
(should (stringp result))
|
||||
(should (string-match-p "\\[\\[file:my-note\\.html\\]" result))))
|
||||
(delete-directory base-dir t))))
|
||||
|
||||
;; ── z/copy-neighbor-attachments ──────────────────────────────────────────────
|
||||
|
||||
(ert-deftest test/copy-neighbor-attachments-copies-matching-dirs ()
|
||||
"Sibling .attachments.* directories should be copied to pub-dir."
|
||||
(let* ((src-dir (make-temp-file "src-" t))
|
||||
(pub-dir (make-temp-file "pub-" t))
|
||||
(att-dir (expand-file-name ".attachments.my-note" src-dir))
|
||||
(att-file (expand-file-name "image.png" att-dir)))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(make-directory att-dir t)
|
||||
(with-temp-file att-file (insert "fake png"))
|
||||
(z/copy-neighbor-attachments src-dir pub-dir)
|
||||
(should (file-exists-p
|
||||
(expand-file-name ".attachments.my-note/image.png" pub-dir))))
|
||||
(delete-directory src-dir t)
|
||||
(delete-directory pub-dir t))))
|
||||
|
||||
(ert-deftest test/copy-neighbor-attachments-ignores-non-matching ()
|
||||
"Directories not starting with .attachments. should be left alone."
|
||||
(let* ((src-dir (make-temp-file "src-" t))
|
||||
(pub-dir (make-temp-file "pub-" t))
|
||||
(other-dir (expand-file-name "regular-dir" src-dir)))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(make-directory other-dir t)
|
||||
(z/copy-neighbor-attachments src-dir pub-dir)
|
||||
(should-not (file-exists-p
|
||||
(expand-file-name "regular-dir" pub-dir))))
|
||||
(delete-directory src-dir t)
|
||||
(delete-directory pub-dir t))))
|
||||
|
||||
(ert-deftest test/copy-neighbor-attachments-no-error-when-none-exist ()
|
||||
"No error should be raised when there are no .attachments.* dirs."
|
||||
(let* ((src-dir (make-temp-file "src-" t))
|
||||
(pub-dir (make-temp-file "pub-" t)))
|
||||
(unwind-protect
|
||||
(should-not (z/copy-neighbor-attachments src-dir pub-dir))
|
||||
(delete-directory src-dir t)
|
||||
(delete-directory pub-dir t))))
|
||||
|
||||
;; ── z/org-html-add-body-classes ──────────────────────────────────────────────
|
||||
;; These tests stub out z/no-sidenotes-file-p so they run without depending on
|
||||
;; full site metadata.
|
||||
|
||||
(ert-deftest test/add-body-classes-adds-no-sidenotes-class ()
|
||||
"Should add class=\"no-sidenotes\" when z/no-sidenotes-file-p is t."
|
||||
(with-temp-org-file "#+TITLE: No sidenotes\n\nContent.\n"
|
||||
(cl-letf (((symbol-function 'z/no-sidenotes-file-p) (lambda (_) t)))
|
||||
(let* ((info (list :input-file temp-file))
|
||||
(output "<html><body><p>hello</p></body></html>")
|
||||
(result (z/org-html-add-body-classes output 'html info)))
|
||||
(should (string-match-p "class=\"no-sidenotes\"" result))))))
|
||||
|
||||
(ert-deftest test/add-body-classes-unchanged-when-no-classes ()
|
||||
"Output should be unmodified when no special classes apply."
|
||||
(with-temp-org-file "#+TITLE: Plain\n\nContent.\n"
|
||||
(cl-letf (((symbol-function 'z/no-sidenotes-file-p) (lambda (_) nil)))
|
||||
(let* ((info (list :input-file temp-file))
|
||||
(output "<html><body><p>hello</p></body></html>")
|
||||
(result (z/org-html-add-body-classes output 'html info)))
|
||||
(should (string= output result))))))
|
||||
|
||||
(ert-deftest test/add-body-classes-ignores-non-html-backend ()
|
||||
"For non-HTML backends the output should pass through unchanged."
|
||||
(with-temp-org-file "#+TITLE: LaTeX\n\nContent.\n"
|
||||
(cl-letf (((symbol-function 'z/no-sidenotes-file-p) (lambda (_) t)))
|
||||
(let* ((info (list :input-file temp-file))
|
||||
(output "\\documentclass{article}")
|
||||
(result (z/org-html-add-body-classes output 'latex info)))
|
||||
(should (string= output result))))))
|
||||
|
||||
;;; build-site-tests.el ends here
|
||||
Reference in New Issue
Block a user