This commit is contained in:
2026-03-20 23:53:41 +00:00
parent 20f770ad59
commit 623727e71c
25 changed files with 2262 additions and 2765 deletions

3
.stignore Normal file
View File

@@ -0,0 +1,3 @@
output
.packages
.org-timestamps

262
build-site-tests.el Normal file
View File

@@ -0,0 +1,262 @@
;;; build-site-tests.el --- ERT unit tests for build-site.el -*- lexical-binding: t; -*-
;; Run with:
;; emacs -Q --batch -l build-site.el -l build-site-tests.el -f ert-run-tests-batch-and-exit
;; Or interactively:
;; M-x load-file RET build-site-tests.el RET
;; M-x ert RET t RET
;;; Code:
(require 'ert)
(require 'org)
;; ── 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 function currently returns nil (known bug:
`when' has no else branch so the body string is not passed through).
Fix: change `when' to `if' with body as the else clause.
This test documents current behaviour; flip the should once fixed."
(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)))
;; BUG: should be (should (string= "<div>body</div>" result))
(should (null 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/wip-file-p and z/no-sidenotes-file-p so they run
;; without the full site infrastructure loaded.
(ert-deftest test/add-body-classes-adds-wip-class ()
"Should add class=\"wip\" to <body> when z/wip-file-p is t."
(with-temp-org-file "#+TITLE: WIP page\n\nContent.\n"
(cl-letf (((symbol-function 'z/wip-file-p) (lambda (_) t))
((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-match-p "class=\"wip\"" result))))))
(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/wip-file-p) (lambda (_) nil))
((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-combines-multiple-classes ()
"Both wip and no-sidenotes classes should appear when both predicates are t."
(with-temp-org-file "#+TITLE: Both\n\nContent.\n"
(cl-letf (((symbol-function 'z/wip-file-p) (lambda (_) t))
((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 "wip" result))
(should (string-match-p "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/wip-file-p) (lambda (_) nil))
((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 function currently returns nil (known bug:
`when' has no else branch so output is not passed through).
Fix: change `when' to `if' with output as the else clause.
This test documents current behaviour; flip the should once fixed."
(with-temp-org-file "#+TITLE: LaTeX\n\nContent.\n"
(cl-letf (((symbol-function 'z/wip-file-p) (lambda (_) t))
((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)))
;; BUG: should be (should (string= output result))
(should (null result))))))
;;; build-site-tests.el ends here

View File

@@ -7,32 +7,127 @@
;;; Commentary: ;;; Commentary:
;; Run this file with: ;; Run this file with:
;; emacs -Q --script build-site.el ;; emacs -Q --script build-site.el
;;
;; Optional env vars:
;; SITE_FORCE=1 Force republish all files (default: incremental)
;; SITE_DRY=1 Parse and prepare only; skip org-publish-all
;;; Code: ;;; Code:
(require 'package) ;; ─────────────────────────────────────────────────────────────────────────────
(defvar site-root ;; 0. Bootstrap: paths and load-path
;; ─────────────────────────────────────────────────────────────────────────────
(defconst z/build-start-time (float-time)
"Wall-clock time when the build started.")
(defconst z/site-root
(file-name-as-directory
(file-name-directory (file-name-directory
(or load-file-name buffer-file-name))) (or load-file-name buffer-file-name)))
"Absolute path to the site root (always ends with /).
This is the single authoritative definition — lisp/* files must NOT
redefine site-root themselves.")
;; Keep the old name around so any stray code still compiles.
(defvaralias 'site-root 'z/site-root)
(defun site-path (path) (defun site-path (path)
(expand-file-name path site-root)) "Expand PATH relative to `z/site-root'."
(expand-file-name path z/site-root))
(add-to-list 'load-path (site-path "lisp"))
(add-to-list 'load-path ;; ─────────────────────────────────────────────────────────────────────────────
(expand-file-name "lisp" ;; 1. Logging helpers (ANSI colours for terminal output)
(file-name-directory ;; ─────────────────────────────────────────────────────────────────────────────
(or load-file-name buffer-file-name))))
(require 'recently-updated) (defconst z/colour-reset "\033[0m")
(require 'tags) (defconst z/colour-bold "\033[1m")
(require 'sidenotes) (defconst z/colour-dim "\033[2m")
(require 'sitemaps) (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")
(setq package-user-dir (expand-file-name "./.packages")) (defun z/log (level fmt &rest args)
(setq package-archives '(("melpa" . "https://melpa.org/packages/") "Emit a coloured build-log line.
LEVEL is one of: info warn error step metric done.
FMT / 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
"" z/colour-reset))
(_ " "))))
(message "%s%s" prefix msg)))
(defun z/log-separator (&optional label)
"Print a coloured 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))))))
;; ─────────────────────────────────────────────────────────────────────────────
;; 2. Package bootstrap
;; ─────────────────────────────────────────────────────────────────────────────
(z/log-separator "Package setup")
(require 'package)
(setq package-user-dir (site-path ".packages"))
(setq package-archives
'(("melpa" . "https://melpa.org/packages/")
("elpa" . "https://elpa.gnu.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)
;; ─────────────────────────────────────────────────────────────────────────────
;; 3. Org / ox requires
;; ─────────────────────────────────────────────────────────────────────────────
(require 'ox-publish) (require 'ox-publish)
(require 'cl-lib) (require 'cl-lib)
(require 'org) (require 'org)
@@ -40,109 +135,136 @@
(require 'ox-html) (require 'ox-html)
(require 'ox-md) (require 'ox-md)
(package-initialize) ;; ─────────────────────────────────────────────────────────────────────────────
(unless package-archive-contents ;; 4. Local library requires (after load-path is set)
(package-refresh-contents)) ;; ─────────────────────────────────────────────────────────────────────────────
(package-install 'htmlize) (z/log-separator "Local libraries")
(add-to-list 'load-path "~/master-folder/org_files/org_web/")
(require 'htmlize)
(defvar z-shared-head (dolist (lib '(recently-updated tags sidenotes sitemaps))
" (condition-case err
<link rel=\"icon\" type=\"image/png\" sizes=\"48x48\" href=\"/assets/icons/icons8-film-tape-100.png\" /> (progn
(require lib)
(z/log 'done "Loaded %s" lib))
(error
(z/log 'error "Failed to load %s: %s" lib (error-message-string err))
(error "Aborting: required library %s missing" lib))))
<link rel=\"stylesheet\" href=\"/assets/styles/style.css\" /> ;; ─────────────────────────────────────────────────────────────────────────────
<link rel=\"stylesheet\" href=\"/assets/styles/bigger-picture.min.css\" /> ;; 5. HTML export settings
<link rel=\"stylesheet\" href=\"/assets/styles/comments.css\" /> ;; ─────────────────────────────────────────────────────────────────────────────
<link rel=\"stylesheet\" href=\"/assets/styles/kanban.css\" />
<link rel=\"stylesheet\" href=\"/assets/styles/org-syntax.css\" />
<link rel=\"stylesheet\" href=\"/assets/styles/misc.css\" />
<link rel=\"stylesheet\" href=\"/assets/styles/toc.css\" />
<link rel=\"stylesheet\" href=\"/assets/styles/media.css\" />
<link rel=\"stylesheet\" href=\"/assets/styles/wird-tracker.css\" />
<script src=\"/assets/scripts/script.js\" defer></script> (setq org-html-htmlize-output-type 'css)
<script src=\"/assets/scripts/lunr.js\" defer></script>
<script src=\"/assets/scripts/competency-status-board.js\" defer></script> (defvar z/shared-head
<script src=\"/assets/scripts/notes.js\" defer></script> (concat
<script src=\"/assets/scripts/comments.js\" defer></script> "<link rel=\"icon\" type=\"image/png\" sizes=\"48x48\""
<script src=\"/assets/scripts/bigger-picture.min.js\" defer></script> " href=\"/assets/icons/icons8-film-tape-100.png\" />\n"
<script src=\"/assets/scripts/search.js\" defer></script> (mapconcat
<script src=\"/assets/scripts/svg-pan-zoom.min.js\" defer></script> (lambda (f)
<script src=\"/assets/scripts/gallery-init.js\" defer></script> (format "<link rel=\"stylesheet\" href=\"/assets/styles/%s\" />" f))
<script src=\"/assets/scripts/sitemap-interactive.js\" defer></script> '("style.css"
<script src=\"/assets/scripts/wird-tracker.js\" defer></script> "bigger-picture.min.css"
" "comments.css"
) "kanban.css"
"org-syntax.css"
"misc.css"
"toc.css"
"media.css"
"wird-tracker.css")
"\n")
"\n"
(mapconcat
(lambda (f)
(format "<script src=\"/assets/scripts/%s\" defer></script>" 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")
"\n"))
"Shared <head> HTML fragment injected into every page.")
;; ─────────────────────────────────────────────────────────────────────────────
;; 6. Global Org macros
;; ─────────────────────────────────────────────────────────────────────────────
(setq org-export-global-macros (setq org-export-global-macros
(append (append
org-export-global-macros
'(("sidenote" '(("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>@@") . "@@html:<label for=\"sn$1\" class=\"margin-toggle sidenote-number\"></label>\
("epigraph" . "@@html:<div class=\"epigraph\"><blockquote>$1<footer>$2</footer></blockquote></div>@@") <input type=\"checkbox\" id=\"sn$1\" class=\"margin-toggle\"/>\
("epigraph_single" . "@@html:<div class=\"epigraph\"><blockquote>$1</blockquote></div>@@") <span class=\"sidenote\">$2</span>@@")
("epigraph3" . "@@html:<div class=\"epigraph\"><blockquote>$1<footer>$2, <cite>$3</cite></footer></blockquote></div>@@") ("epigraph"
("kbd" . "@@html:<kbd>$1</kbd>@@@@latex:\\texttt{$1}@@") . "@@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" ("margimg"
. "@@html:<aside class=\"marginnote\"><figure class=\"mn-fig\"><img src=\"$1\" alt=\"$2\" class=\"mn-img\" loading=\"lazy\" decoding=\"async\"/>$3</figure></aside>@@") . "@@html:<aside class=\"marginnote\"><figure class=\"mn-fig\">\
("countdown" . "@@html:<time class=\"countdown\" datetime=\"$1\" data-label=\"$2\"></time>@@") <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>@@"))))
;; ─────────────────────────────────────────────────────────────────────────────
;; 7. Preamble / postamble
;; ─────────────────────────────────────────────────────────────────────────────
org-export-global-macros))) (defvar z/preamble
"<div class=\"banner-header\">
(defvar z-preamble
"
<div class=\"banner-header\">
<a href=\"/\"><img src=\"/assets/images/gr.png\" alt=\"Site Logo\" class=\"banner-logo\" /></a> <a href=\"/\"><img src=\"/assets/images/gr.png\" alt=\"Site Logo\" class=\"banner-logo\" /></a>
<nav> <nav>
<a href=\"/\">Home | </a> <a href=\"/\">Home | </a>
<a href=\"/blogs/blogs-list.html\">Blogs | </a> <a href=\"/blogs/blogs-list.html\">Blogs | </a>
<a href=\"/posts/career/career-list.html\">Career | </a> <a href=\"/posts/career/career-list.html\">Career | </a>
<a href=\"https://zone.zainezq.com\">Dashboard</a> <a href=\"https://zone.zainezq.com\">Dashboard</a>
<input type=\"search\" id=\"search-input\" placeholder=\"Search…\" aria-label=\"Search notes\" />
<input type=\"search\\\" id=\"search-input\" placeholder=\"Search…\" aria-label=\"Search notes\" />
<button id=\"search-btn\" aria-label=\"Search\">🔍</button> <button id=\"search-btn\" aria-label=\"Search\">🔍</button>
</nav> </nav>
<button class=\"theme-toggle\" id=\"theme-toggle\" type=\"button\" aria-label=\"Toggle dark mode\">🌗 Theme</button> <button class=\"theme-toggle\" id=\"theme-toggle\" type=\"button\" aria-label=\"Toggle dark mode\">🌗 Theme</button>
</div> </div>
<div id=\"updated\">Updated: %C</div> <div id=\"updated\">Updated: %C</div>
")
" (defvar z/postamble
)
(defvar z-postamble
"<footer> "<footer>
<div class=\"copyright-container\"> <div class=\"copyright-container\">
<div class=\"copyright\"> <div class=\"copyright\">
Copyright &copy; 2022-2026 Zaine Qayyum. All rights reserved unless otherwise noted.</div></div> Copyright &copy; 2022-2026 Zaine Qayyum. All rights reserved unless otherwise noted.</div></div>
<div class=\"generated\"> <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> 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> </div>
</footer>") </footer>")
;; ─────────────────────────────────────────────────────────────────────────────
;; 8. Comments support
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/comments-file-p (file) (defun z/comments-file-p (file)
"Return non-nil if FILE has comments enabled. "Return non-nil if FILE has #+COMMENTS: t."
A file has comments if:
- It has a #+COMMENTS: keyword with value \"t\" (case-insensitive)."
(when (file-exists-p file) (when (file-exists-p file)
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert-file-contents file)
(org-mode) (org-mode)
(let* ((keywords (org-collect-keywords '("COMMENTS"))) (let* ((keywords (org-collect-keywords '("COMMENTS")))
(comments (cadr (assoc "COMMENTS" keywords)))) (val (cadr (assoc "COMMENTS" keywords))))
(print keywords) (and val
(string-match-p "^\\s-*t\\s-*$" (downcase val)))))))
(and comments
(string-match-p "^\\s-*t\\s-*$"
(downcase comments)))))))
(defun z/comments-file-slug (file) (defun z/comments-file-slug (file)
"Return page slug from #+SLUG: or fallback to filename." "Return page slug from #+SLUG: or fallback to filename base."
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert-file-contents file)
(org-mode) (org-mode)
@@ -153,41 +275,36 @@ A file has comments if:
(file-name-base file))))) (file-name-base file)))))
(defun z/org-html-insert-comments-into-body (body backend info) (defun z/org-html-insert-comments-into-body (body backend info)
"Insert comments section at the end of the document body." "Append a comments section to BODY for files that opt in."
(when (org-export-derived-backend-p backend 'html) (when (org-export-derived-backend-p backend 'html)
(let ((input-file (plist-get info :input-file))) (let ((input-file (plist-get info :input-file)))
(if (and input-file (if (and input-file (z/comments-file-p input-file))
(z/comments-file-p input-file))
(let* ((slug (z/comments-file-slug input-file)) (let* ((slug (z/comments-file-slug input-file))
(comments-html (html (format
(format "\n<section id=\"comments\" class=\"comments\" data-slug=\"%s\">
"
<section id=\"comments\" class=\"comments\" data-slug=\"%s\">
<h2>Comments</h2> <h2>Comments</h2>
<div id=\"comments-list\" class=\"comments-list\"> <div id=\"comments-list\" class=\"comments-list\">
<noscript>Please enable JavaScript to view comments.</noscript> <noscript>Please enable JavaScript to view comments.</noscript>
</div> </div>
<form id=\"comment-form\" class=\"comment-form\"> <form id=\"comment-form\" class=\"comment-form\">
<label class=\"comment-author\"> <label class=\"comment-author\">
<span>Name (optional)</span> <span>Name (optional)</span>
<input type=\"text\" name=\"author\"/> <input type=\"text\" name=\"author\"/>
</label> </label>
<label class=\"comment-content\"> <label class=\"comment-content\">
<span>Your comment</span> <span>Your comment</span>
<textarea name=\"content\" required></textarea> <textarea name=\"content\" required></textarea>
</label> </label>
<button type=\"submit\">Post comment</button> <button type=\"submit\">Post comment</button>
</form> </form>
</section> </section>\n"
"
slug))) slug)))
(concat body comments-html)) (concat body html))
body)))) body))))
;; ─────────────────────────────────────────────────────────────────────────────
;; 9. Body-class injection (WIP / no-sidenotes)
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/org-html-add-body-classes (output backend info) (defun z/org-html-add-body-classes (output backend info)
"Add layout-related classes to <body> based on file metadata." "Add layout-related classes to <body> based on file metadata."
@@ -196,11 +313,9 @@ A file has comments if:
(classes (classes
(delq nil (delq nil
(list (list
(when (and input-file (when (and input-file (z/wip-file-p input-file))
(z/wip-file-p input-file))
"wip") "wip")
(when (and input-file (when (and input-file (z/no-sidenotes-file-p input-file))
(z/no-sidenotes-file-p input-file))
"no-sidenotes"))))) "no-sidenotes")))))
(if classes (if classes
(replace-regexp-in-string (replace-regexp-in-string
@@ -215,33 +330,31 @@ A file has comments if:
(add-to-list 'org-export-filter-body-functions (add-to-list 'org-export-filter-body-functions
#'z/org-html-insert-comments-into-body) #'z/org-html-insert-comments-into-body)
(defun z/lima--ensure-sitemap-file (project) ;; ─────────────────────────────────────────────────────────────────────────────
"Ensure the sitemap source file exists under the project's base directory." ;; 10. Custom z-html backend
(let* ((base-dir (file-name-as-directory ;; ─────────────────────────────────────────────────────────────────────────────
(org-publish-property :base-directory project)))
(fname (or (org-publish-property :sitemap-filename project) (org-export-define-derived-backend 'z-html 'html
"lima-list.org")) :filters-alist '((:filter-final-output . z/insert-filetags-after-title)))
(title (or (org-publish-property :sitemap-title project)
"Lima")) (defun z/z-publish-to-html (plist filename pub-dir)
(sitemap-path (expand-file-name fname base-dir))) "Publish FILENAME to HTML using the z-html backend."
;; If file missing or you want to always regenerate, write header. (org-publish-org-to 'z-html filename ".html" plist pub-dir))
(unless (file-exists-p sitemap-path)
(with-temp-file sitemap-path ;; ─────────────────────────────────────────────────────────────────────────────
(insert "#+TITLE: " title "\n" ;; 11. Lima project helpers
"#+OPTIONS: toc:nil num:nil\n\n"))))) ;; ─────────────────────────────────────────────────────────────────────────────
(defun z/lima-sitemap-format-entry (entry style project) (defun z/lima-sitemap-format-entry (entry style project)
"Format sitemap entry for Lima; skip dirs, keep nested paths, and prefix /lima/." "Format a sitemap entry for Lima; skip directories."
(let* ((file (if (listp entry) (car entry) entry)) (let* ((file (if (listp entry) (car entry) entry))
(base-dir (file-name-as-directory (base-dir (file-name-as-directory
(org-publish-property :base-directory project))) (org-publish-property :base-directory project)))
;; Ensure we work with an absolute file path under base-dir
(abs (if (file-name-absolute-p file) (abs (if (file-name-absolute-p file)
file file
(expand-file-name file base-dir)))) (expand-file-name file base-dir))))
;; Skip directories
(unless (file-directory-p abs) (unless (file-directory-p abs)
(let* ((rel (file-relative-name abs base-dir)) ;; guaranteed no “…/..” backtracking now (let* ((rel (file-relative-name abs base-dir))
(rel-noext (file-name-sans-extension rel)) (rel-noext (file-name-sans-extension rel))
(title (org-publish-find-title abs project))) (title (org-publish-find-title abs project)))
(format "[[file:%s.html][%s]]" (format "[[file:%s.html][%s]]"
@@ -249,69 +362,47 @@ A file has comments if:
(or title (file-name-nondirectory rel-noext))))))) (or title (file-name-nondirectory rel-noext)))))))
(defun z/copy-neighbor-attachments (source-dir pub-dir) (defun z/copy-neighbor-attachments (source-dir pub-dir)
"Copy sibling directories named .attachments.* from SOURCE-DIR to PUB-DIR." "Copy sibling .attachments.* directories from SOURCE-DIR into PUB-DIR."
(let ((dirs (directory-files source-dir t "^\\.attachments\\..+"))) (dolist (d (directory-files source-dir t "^\\.attachments\\..+"))
(dolist (d dirs)
(when (file-directory-p d) (when (file-directory-p d)
(let* ((target (expand-file-name (file-name-nondirectory d) pub-dir))) (let ((target (expand-file-name (file-name-nondirectory d) pub-dir)))
(make-directory target t) (make-directory target t)
;; copy-directory: (DIRECTORY NEWNAME &optional KEEP-TIME PARENTS COPY-CONTENTS) (copy-directory d target t t t)))))
(copy-directory d target t t t))))))
(defun z/publish-lima-file (plist filename pub-dir) (defun z/publish-lima-file (plist filename pub-dir)
"Publish Org or Markdown file from lima directory." "Publish an Org or Markdown file from the lima directory."
(let* ((ext (downcase (or (file-name-extension filename) ""))) (let* ((ext (downcase (or (file-name-extension filename) "")))
(base (file-name-base filename)) (base (file-name-base filename))
(src-dir (file-name-directory filename))) (src-dir (file-name-directory filename)))
(cond (cond
;; ORG FILES (publish as-is) ;; ── Org files ──────────────────────────────────────────────────────────
((string= ext "org") ((string= ext "org")
;; Ensure sibling .attachments.* are published
(z/copy-neighbor-attachments src-dir pub-dir) (z/copy-neighbor-attachments src-dir pub-dir)
(org-publish-org-to 'z-html filename ".html" plist pub-dir)) (org-publish-org-to 'z-html filename ".html" plist pub-dir))
;; MARKDOWN FILES ;; ── Markdown files ─────────────────────────────────────────────────────
((string= ext "md") ((string= ext "md")
(let* ((temp-org (let* ((tmp-dir (make-temp-file "lima-build-" t))
(expand-file-name (temp-org (expand-file-name (concat base ".org") tmp-dir)))
(concat base ".org") ;; Markdown → Org
(make-temp-file "lima-build-" t)))) (let ((rc (call-process "pandoc" nil nil nil
filename "-f" "markdown" "-t" "org" "-o" temp-org)))
;; Convert Markdown → Org with pandoc (unless (zerop rc)
(call-process "pandoc" nil nil nil (z/log 'error "pandoc failed (rc=%d) for %s" rc filename)
filename "-f" "markdown" "-t" "org" "-o" temp-org) (error "pandoc conversion failed for %s" filename)))
;; Prepend front matter
;; Ensure #+TITLE exists
;; Ensure front matter at top of temp-org
(with-temp-buffer (with-temp-buffer
(insert-file-contents temp-org) (insert-file-contents temp-org)
;; Build values
(let* ((title base)
(slug base)
(date (format-time-string "<%Y-%m-%d %a %H:%M>")))
(goto-char (point-min)) (goto-char (point-min))
(insert (format "#+TITLE: %s\n#+OPTIONS: num:nil\n#+DATE: %s\n#+COMMENTS: t\n#+SLUG: %s\n\n"
;; Insert front matter base
;; (Always ensure they are at the absolute top) (format-time-string "<%Y-%m-%d %a %H:%M>")
(insert "#+TITLE: " title "\n" base))
"#+OPTIONS: num:nil\n"
"#+DATE: " date "\n"
"#+COMMENTS: t\n"
"#+SLUG: " slug "\n\n"))
;; Write back to file
(write-region (point-min) (point-max) temp-org)) (write-region (point-min) (point-max) temp-org))
;; Publish
;; Ensure sibling .attachments.* are published
(z/copy-neighbor-attachments src-dir pub-dir) (z/copy-neighbor-attachments src-dir pub-dir)
;; Publish using ORIGINAL base name
(let ((output-file (expand-file-name (concat base ".html") 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) (org-publish-org-to 'z-html temp-org ".html" plist pub-dir)
;; temp-org base may differ; normalize to requested base
(let ((generated (expand-file-name (let ((generated (expand-file-name
(concat (file-name-base temp-org) ".html") (concat (file-name-base temp-org) ".html")
pub-dir))) pub-dir)))
@@ -319,24 +410,24 @@ A file has comments if:
(not (string-equal generated output-file))) (not (string-equal generated output-file)))
(rename-file generated output-file t)))))) (rename-file generated output-file t))))))
;; ── Fallback: treat as attachment ──────────────────────────────────────
(t (t
;; Default: treat as attachment
(org-publish-attachment plist filename pub-dir))))) (org-publish-attachment plist filename pub-dir)))))
;; ─────────────────────────────────────────────────────────────────────────────
(setq org-html-htmlize-output-type 'css) ;; 12. Preparation hooks
;; ─────────────────────────────────────────────────────────────────────────────
(org-export-define-derived-backend 'z-html 'html
:filters-alist '((:filter-final-output . z/insert-filetags-after-title)))
(defun z/org-main-prep (_project) (defun z/org-main-prep (_project)
(z/generate-recently-updated-org 26)) "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/z-publish-to-html (plist filename pub-dir) ;; ─────────────────────────────────────────────────────────────────────────────
"Publish FILENAME to HTML using the z-html backend." ;; 13. Publishing project alist
(org-publish-org-to 'z-html filename ".html" plist pub-dir)) ;; ─────────────────────────────────────────────────────────────────────────────
;; Define the publishing project
(setq org-publish-project-alist (setq org-publish-project-alist
`(("org-main" `(("org-main"
:recursive t :recursive t
@@ -348,11 +439,18 @@ A file has comments if:
:sitemap-filename "sitemap.org" :sitemap-filename "sitemap.org"
:sitemap-title "Sitemap" :sitemap-title "Sitemap"
:sitemap-sort-files chronologically :sitemap-sort-files chronologically
:html-preamble ,z-preamble :html-preamble ,z/preamble
:html-postamble ,z-postamble :html-postamble ,z/postamble
:html-head ,z-shared-head :html-head ,z/shared-head
:preparation-function z/org-main-prep) :preparation-function z/org-main-prep)
("org-assets"
:base-directory ,(site-path "assets/")
:base-extension "css\\|js\\|png\\|jpg\\|gif\\|svg\\|pdf\\|woff\\|woff2\\|ttf"
:publishing-directory ,(site-path "output/assets/")
:recursive t
:publishing-function org-publish-attachment)
("org-categories-sitemap" ("org-categories-sitemap"
:recursive t :recursive t
:base-directory ,(site-path "home/") :base-directory ,(site-path "home/")
@@ -362,9 +460,9 @@ A file has comments if:
:sitemap-filename "categories.org" :sitemap-filename "categories.org"
:sitemap-title "Categories" :sitemap-title "Categories"
:sitemap-function z/categories-sitemap :sitemap-function z/categories-sitemap
:html-preamble ,z-preamble :html-preamble ,z/preamble
:html-postamble ,z-postamble :html-postamble ,z/postamble
:html-head ,z-shared-head) :html-head ,z/shared-head)
("org-posts" ("org-posts"
:base-directory ,(site-path "posts/") :base-directory ,(site-path "posts/")
@@ -377,15 +475,15 @@ A file has comments if:
:html-validation-link nil :html-validation-link nil
:with-toc t :with-toc t
:section-numbers t :section-numbers t
:html-preamble ,z-preamble :html-preamble ,z/preamble
:html-postamble ,z-postamble :html-postamble ,z/postamble
:auto-sitemap t :auto-sitemap t
:sitemap-filename "posts-list.org" :sitemap-filename "posts-list.org"
:sitemap-title "Posts List" :sitemap-title "Posts List"
:sitemap-style list :sitemap-style list
:sitemap-function z/posts-sitemap :sitemap-function z/posts-sitemap
:sitemap-sort-files anti-chronologically :sitemap-sort-files anti-chronologically
:html-head ,z-shared-head) :html-head ,z/shared-head)
("org-blogs" ("org-blogs"
:base-directory ,(site-path "blogs/") :base-directory ,(site-path "blogs/")
@@ -396,15 +494,15 @@ A file has comments if:
:with-author nil :with-author nil
:with-creator nil :with-creator nil
:html-validation-link nil :html-validation-link nil
:html-preamble ,z-preamble :html-preamble ,z/preamble
:html-postamble ,z-postamble :html-postamble ,z/postamble
:auto-sitemap t :auto-sitemap t
:sitemap-filename "blogs-list.org" :sitemap-filename "blogs-list.org"
:sitemap-title "Blogs List" :sitemap-title "Blogs List"
:sitemap-style list :sitemap-style list
:sitemap-function z/blogs-grouped-sitemap :sitemap-function z/blogs-grouped-sitemap
:sitemap-sort-files anti-chronologically :sitemap-sort-files anti-chronologically
:html-head ,z-shared-head) :html-head ,z/shared-head)
("org-books" ("org-books"
:base-directory ,(site-path "books/") :base-directory ,(site-path "books/")
@@ -412,49 +510,15 @@ A file has comments if:
:recursive t :recursive t
:base-extension "org" :base-extension "org"
:publishing-function z/z-publish-to-html :publishing-function z/z-publish-to-html
:html-preamble ,z-preamble :html-preamble ,z/preamble
:html-postamble ,z-postamble :html-postamble ,z/postamble
:auto-sitemap t :auto-sitemap t
:sitemap-filename "books-list.org" :sitemap-filename "books-list.org"
:sitemap-title "Books List" :sitemap-title "Books List"
:sitemap-style list :sitemap-style list
:sitemap-function z/books-sitemap :sitemap-function z/books-sitemap
:sitemap-sort-files anti-chronologically :sitemap-sort-files anti-chronologically
:html-head ,z-shared-head) :html-head ,z/shared-head)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ("org-2025" ;;
;; :base-directory ,(site-path "blogs/2025/") ;;
;; :publishing-directory ,(site-path "output/blogs/2025/") ;;
;; :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 "2025-list.org" ;;
;; :sitemap-title "2025 List" ;;
;; :sitemap-style list ;;
;; :sitemap-function z/2025-sitemap ;;
;; :sitemap-sort-files anti-chronologically ;;
;; :html-head ,z-shared-head) ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ("org-2026"
;; :base-directory ,(site-path "blogs/2026/")
;; :publishing-directory ,(site-path "output/blogs/2026/")
;; :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 "2026-list.org"
;; :sitemap-title "2026 List"
;; :sitemap-style list
;; :sitemap-function z/2026-sitemap
;; :sitemap-sort-files anti-chronologically
;; :html-head ,z-shared-head)
("org-career" ("org-career"
:base-directory ,(site-path "posts/career/") :base-directory ,(site-path "posts/career/")
@@ -462,15 +526,15 @@ A file has comments if:
:recursive t :recursive t
:base-extension "org" :base-extension "org"
:publishing-function z/z-publish-to-html :publishing-function z/z-publish-to-html
:html-preamble ,z-preamble :html-preamble ,z/preamble
:html-postamble ,z-postamble :html-postamble ,z/postamble
:auto-sitemap t :auto-sitemap t
:sitemap-filename "career-list.org" :sitemap-filename "career-list.org"
:sitemap-title "Career List" :sitemap-title "Career List"
:sitemap-style list :sitemap-style list
:sitemap-function z/career-sitemap :sitemap-function z/career-sitemap
:sitemap-sort-files anti-chronologically :sitemap-sort-files anti-chronologically
:html-head ,z-shared-head) :html-head ,z/shared-head)
("wip-pages" ("wip-pages"
:base-directory ,(site-path "") :base-directory ,(site-path "")
@@ -478,15 +542,15 @@ A file has comments if:
:recursive t :recursive t
:base-extension "org" :base-extension "org"
:publishing-function z/z-publish-to-html :publishing-function z/z-publish-to-html
:html-preamble ,z-preamble :html-preamble ,z/preamble
:html-postamble ,z-postamble :html-postamble ,z/postamble
:auto-sitemap t :auto-sitemap t
:sitemap-filename "wip.org" :sitemap-filename "wip.org"
:sitemap-title "Work in progress" :sitemap-title "Work in progress"
:sitemap-style list :sitemap-style list
:sitemap-function z/wip-sitemap :sitemap-function z/wip-sitemap
:sitemap-sort-files anti-chronologically :sitemap-sort-files anti-chronologically
:html-head ,z-shared-head) :html-head ,z/shared-head)
("org-tags" ("org-tags"
:base-directory ,(site-path "tags/") :base-directory ,(site-path "tags/")
@@ -494,9 +558,9 @@ A file has comments if:
:recursive t :recursive t
:base-extension "org" :base-extension "org"
:publishing-function org-html-publish-to-html :publishing-function org-html-publish-to-html
:html-preamble ,z-preamble :html-preamble ,z/preamble
:html-postamble ,z-postamble :html-postamble ,z/postamble
:html-head ,z-shared-head) :html-head ,z/shared-head)
("org-lima" ("org-lima"
:base-directory ,(site-path "lima/") :base-directory ,(site-path "lima/")
@@ -507,29 +571,139 @@ A file has comments if:
:with-author nil :with-author nil
:with-creator nil :with-creator nil
:html-validation-link nil :html-validation-link nil
:html-preamble ,z-preamble :html-preamble ,z/preamble
:html-postamble ,z-postamble :html-postamble ,z/postamble
:sitemap-filename "lima-list.org" :sitemap-filename "lima-list.org"
:auto-sitemap t :auto-sitemap t
:sitemap-title "Lima" :sitemap-title "Lima"
:sitemap-style list :sitemap-style list
:sitemap-sort-files anti-chronologically :sitemap-sort-files anti-chronologically
:sitemap-format-entry z/lima-sitemap-format-entry :sitemap-format-entry z/lima-sitemap-format-entry
:html-head ,z-shared-head) :html-head ,z/shared-head)))
("org-assets" ;; ─────────────────────────────────────────────────────────────────────────────
:base-directory ,(site-path "assets/") ;; 14. Pre-build clean-up (opt-in via SITE_CLEAN=1)
:base-extension "css\\|js\\|png\\|jpg\\|gif\\|svg\\|pdf\\|woff\\|woff2\\|ttf" ;; ─────────────────────────────────────────────────────────────────────────────
:publishing-directory ,(site-path "output/assets/") ;;
:recursive t ;; IMPORTANT: output/ and .org-timestamps/ are a matched pair.
:publishing-function org-publish-attachment))) ;; .org-timestamps/ is org-publish's cache of every file's last-published
;; mtime. If output/ is wiped without also wiping .org-timestamps/, the next
;; incremental build sees "cache says up-to-date" but the output file is gone,
;; so it silently skips the file. That is why assets/ and index.html vanished.
;;
;; Rule: whenever output/ is deleted, .org-timestamps/ must be deleted too.
(delete-directory (site-path "output/") t) (z/log-separator "Pre-build")
(delete-directory (site-path "tags/") t)
(message "Directory deleted")
(z/write-tag-pages) (defun z/wipe-build-dirs ()
(org-publish-all t) "Delete output/, tags/, and .org-timestamps/ together."
(message "Build complete!") (dolist (dir (list (site-path "output/")
(site-path "tags/")
(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.
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/"))
(push "output/assets/" missing))
(unless (or (file-exists-p (site-path "output/index.html"))
(file-exists-p (site-path "output/sitemap.html")))
(push "output/index.html (or sitemap.html)" missing))
(dolist (m missing)
(z/log 'warn "Integrity check: missing %s" m))
(null missing)))
(cond
;; ── Explicit clean requested ───────────────────────────────────────────────
((getenv "SITE_CLEAN")
(z/log 'warn "SITE_CLEAN=1 — wiping output/, tags/, and .org-timestamps/")
(z/wipe-build-dirs)
(setenv "SITE_FORCE" "1"))
;; ── Output looks incomplete — cache is stale ──────────────────────────────
;; Catches the case where output/ was wiped externally (git clean, manual rm,
;; Syncthing conflict) without clearing .org-timestamps/. Without this guard
;; org-publish would silently skip every "up-to-date" file and produce a
;; broken site with missing assets and pages.
((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"))
;; ── Normal incremental build ──────────────────────────────────────────────
(t
(z/log 'info "Incremental build — output/ looks complete")))
;; ─────────────────────────────────────────────────────────────────────────────
;; 15. Tag pages
;; ─────────────────────────────────────────────────────────────────────────────
(z/log-separator "Tag generation")
(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"))))
;; ─────────────────────────────────────────────────────────────────────────────
;; 16. Publish
;; ─────────────────────────────────────────────────────────────────────────────
(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
(z/with-timing "org-publish-all"
(org-publish-all force))
(error
(z/log 'error "org-publish-all failed: %s" (error-message-string err))
(error "Build failed")))))
;; ─────────────────────────────────────────────────────────────────────────────
;; 17. Build summary
;; ─────────────────────────────────────────────────────────────────────────────
(z/log-separator "Build summary")
(let* ((elapsed (- (float-time) z/build-start-time))
(out-dir (site-path "output/"))
(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/")))
(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 ✓"))
;;; build-site.el ends here ;;; build-site.el ends here

View File

@@ -1,30 +1,30 @@
#+TITLE: Recently Updated #+TITLE: Recently Updated
#+OPTIONS: toc:nil num:nil #+OPTIONS: toc:nil num:nil
* Recently Updated (top 26 files - per lima's request) * Recently Updated (top 26 files)
- [[file:home/wird-tracker.org][Wird Tracker]] @@html:<span class="post-date">2026-03-19 16:05</span>@@ - [[file:home/wird-tracker.org][Wird Tracker]] @@html:<span class="post-date">2026-03-19 18:26</span>@@
- [[file:blogs/2026/03-march/setting-a-wird-tracker-19-03.org][Setting a Wird Tracker]] @@html:<span class="post-date">2026-03-19 13:57</span>@@ - [[file:blogs/2026/03-march/setting-a-wird-tracker-19-03.org][Setting a Wird Tracker]] @@html:<span class="post-date">2026-03-19 13:15</span>@@
- [[file:index.org][Home Page]] @@html:<span class="post-date">2026-03-19 13:10</span>@@
- [[file:home/guide/wird-tracker-guide.org][Wird Tracker — Technical Guide]] @@html:<span class="post-date">2026-03-19 12:43</span>@@ - [[file:home/guide/wird-tracker-guide.org][Wird Tracker — Technical Guide]] @@html:<span class="post-date">2026-03-19 12:43</span>@@
- [[file:blogs/2026/03-march/fixing-the-dag-18-03.org][DAG fixes]] @@html:<span class="post-date">2026-03-19 10:42</span>@@ - [[file:blogs/2026/03-march/fixing-the-dag-18-03.org][DAG fixes]] @@html:<span class="post-date">2026-03-18 15:01</span>@@
- [[file:blogs/2026/03-march/feeling-sleepy.org][Feeling extremely sleepy]] @@html:<span class="post-date">2026-03-19 10:41</span>@@ - [[file:blogs/2026/03-march/feeling-sleepy.org][Feeling extremely sleepy]] @@html:<span class="post-date">2026-03-16 16:18</span>@@
- [[file:blogs/2026/03-march/oversleeping-16-03.org][Oversleeping and missing a meeting...]] @@html:<span class="post-date">2026-03-16 12:17</span>@@ - [[file:blogs/2026/03-march/oversleeping-16-03.org][Oversleeping and missing a meeting...]] @@html:<span class="post-date">2026-03-16 11:21</span>@@
- [[file:blogs/2026/03-march/15-03-week-review.org][[15-03-2026] - Weekly Review]] @@html:<span class="post-date">2026-03-12 16:31</span>@@ - [[file:blogs/2026/03-march/15-03-week-review.org][[15-03-2026] - Weekly Review]] @@html:<span class="post-date">2026-03-15 12:00</span>@@
- [[file:blogs/2026/03-march/08-03-week-review.org][[08-03-2026] - Weekly Review]] @@html:<span class="post-date">2026-03-12 16:17</span>@@ - [[file:posts/career/ha-dr.org][High Availability, Disaster Recovery and Business Continuity]] @@html:<span class="post-date">2026-03-11 17:18</span>@@
- [[file:posts/career/javascript.org][Understands the Javascript language]] @@html:<span class="post-date">2026-03-11 17:20</span>@@ - [[file:posts/career/javascript.org][Understands the Javascript language]] @@html:<span class="post-date">2026-03-11 16:52</span>@@
- [[file:posts/career/ha-dr.org][High Availability, Disaster Recovery and Business Continuity]] @@html:<span class="post-date">2026-03-11 17:19</span>@@
- [[file:posts/career/restful-api.org][Restful API]] @@html:<span class="post-date">2026-03-08 17:37</span>@@
- [[file:home/status.org][Competency Status Board]] @@html:<span class="post-date">2026-03-08 16:28</span>@@ - [[file:home/status.org][Competency Status Board]] @@html:<span class="post-date">2026-03-08 16:28</span>@@
- [[file:blogs/2026/02-february/27-02-26.org][Journeys rambles again...]] @@html:<span class="post-date">2026-03-07 16:33</span>@@ - [[file:blogs/2026/03-march/08-03-week-review.org][[08-03-2026] - Weekly Review]] @@html:<span class="post-date">2026-03-08 12:00</span>@@
- [[file:blogs/2026/03-march/01-03-week-review.org][[01-03-2026] - Weekly Review]] @@html:<span class="post-date">2026-03-07 12:45</span>@@ - [[file:blogs/2026/03-march/01-03-week-review.org][[01-03-2026] - Weekly Review]] @@html:<span class="post-date">2026-03-01 12:00</span>@@
- [[file:posts/career/database-permissions.org][Database Permissions, Roles, and Accounts]] @@html:<span class="post-date">2026-03-05 13:06</span>@@ - [[file:blogs/2026/02-february/27-02-26.org][Journeys rambles again...]] @@html:<span class="post-date">2026-02-27 17:12</span>@@
- [[file:posts/career/monitoring-and-logging.org][Monitoring and Logging]] @@html:<span class="post-date">2026-03-05 12:58</span>@@ - [[file:blogs/2026/02-february/26-02-26.org][Starting the Journeys Upgrade]] @@html:<span class="post-date">2026-02-26 17:32</span>@@
- [[file:posts/career/pipelines.org][Pipelines and how they work (as well as CI/CD)]] @@html:<span class="post-date">2026-03-05 11:52</span>@@ - [[file:blogs/2026/02-february/24-02-26.org][Integration tests failing (sob)]] @@html:<span class="post-date">2026-02-24 16:55</span>@@
- [[file:blogs/2026/02-february/third-meeting.org][Third Meeting with lima :)]] @@html:<span class="post-date">2026-03-03 12:02</span>@@ - [[file:blogs/2026/02-february/22-02-week-review.org][[22-02-2026] - Weekly Review]] @@html:<span class="post-date">2026-02-22 12:00</span>@@
- [[file:blogs/2026/02-february/22-02-week-review.org][[22-02-2026] - Weekly Review]] @@html:<span class="post-date">2026-02-27 17:07</span>@@ - [[file:posts/career/restful-api.org][Restful API]] @@html:<span class="post-date">2026-02-15 23:00</span>@@
- [[file:blogs/2026/02-february/26-02-26.org][Starting the Journeys Upgrade]] @@html:<span class="post-date">2026-02-26 17:37</span>@@ - [[file:blogs/2026/02-february/15-02-week-review.org][[15-02-2026] - Weekly Review]] @@html:<span class="post-date">2026-02-15 12:00</span>@@
- [[file:blogs/2026/02-february/24-02-26.org][Integration tests failing (sob)]] @@html:<span class="post-date">2026-02-24 17:00</span>@@
- [[file:home/backlog.org][Backlog]] @@html:<span class="post-date">2026-02-23 16:40</span>@@
- [[file:blogs/2026/02-february/15-02-week-review.org][[15-02-2026] - Weekly Review]] @@html:<span class="post-date">2026-02-23 10:02</span>@@
- [[file:home/services.org][Service]] @@html:<span class="post-date">2026-02-11 13:26</span>@@ - [[file:home/services.org][Service]] @@html:<span class="post-date">2026-02-11 13:26</span>@@
- [[file:blogs/2026/02-february/08-02-week-review.org][[08-02-2026] - Weekly Review]] @@html:<span class="post-date">2026-02-11 12:20</span>@@ - [[file:blogs/2026/02-february/08-02-week-review.org][[08-02-2026] - Weekly Review]] @@html:<span class="post-date">2026-02-08 12:00</span>@@
- [[file:blogs/2026/02-february/third-meeting.org][Third Meeting with lima :)]] @@html:<span class="post-date">2026-02-01 12:00</span>@@
- [[file:blogs/2026/02-february/01-02-week-review.org][[01-02-2026] - Weekly Review]] @@html:<span class="post-date">2026-02-01 12:00</span>@@
- [[file:blogs/2026/01-january/25-01-week-review.org][[25-01-2026] - Weekly Review]] @@html:<span class="post-date">2026-01-25 12:00</span>@@
- [[file:posts/career/pipelines.org][Pipelines and how they work (as well as CI/CD)]] @@html:<span class="post-date">2026-01-18 23:00</span>@@
- [[file:posts/career/monitoring-and-logging.org][Monitoring and Logging]] @@html:<span class="post-date">2026-01-18 23:00</span>@@
- [[file:posts/career/database-permissions.org][Database Permissions, Roles, and Accounts]] @@html:<span class="post-date">2026-01-18 23:00</span>@@

View File

@@ -1,115 +1,101 @@
;;; recently-updated.el --- Generate recently-updated.org -*- lexical-binding: t; -*- ;;; recently-updated.el --- Generate recently-updated.org -*- lexical-binding: t; -*-
;;; Commentary:
;; Generates home/recently-updated.org listing the N most recently touched
;; Org files in the site tree.
;;
;; Sort order: #+DATE if parseable, otherwise file modification time.
;; This means intentionally dated pages float correctly, while undated
;; pages fall back to when they were last touched on disk.
;;
;; NOTE: Do NOT define `site-root' here. build-site.el owns that definition.
;;; Code:
(require 'cl-lib) (require 'cl-lib)
(require 'org) (require 'org)
(defvar site-root
(file-name-directory
(or load-file-name buffer-file-name)))
(defvar z-org-root ;; ── Omit predicate ────────────────────────────────────────────────────────────
(file-name-as-directory site-root)
"Root directory of the Org source files.")
;; Which Org files should be skipped for Recently Updated (defconst z/recent-omit-names
(defun z/recent-omit-org-p (rel-org) '("sitemap.org"
"Return non-nil if REL-ORG (relative to `z-org-root`) should not be listed."
(let* ((name (file-name-nondirectory rel-org)))
(or
;; assets-ish / tags
(string-prefix-p "assets/" rel-org)
(string-match-p "/assets/" rel-org)
(string-prefix-p "tags/" rel-org)
(string-match-p "/tags/" rel-org)
;; generated/meta orgs
(member name '("sitemap.org"
"categories.org" "categories.org"
"recently-updated.org" "recently-updated.org"
"wip.org" "wip.org")
)) "Org files that are always excluded from the recently-updated list.")
;; any *-list.org sitemaps (posts-list.org, blogs-list.org, etc.) (defun z/recent-omit-org-p (rel-org)
"Return non-nil if REL-ORG (relative to site root) should be excluded."
(let ((name (file-name-nondirectory rel-org)))
(or
;; Static asset directories
(string-prefix-p "assets/" rel-org)
(string-match-p "/assets/" rel-org)
;; Tag pages
(string-prefix-p "tags/" rel-org)
(string-match-p "/tags/" rel-org)
;; Known generated files
(member name z/recent-omit-names)
;; Any *-list.org sitemaps
(string-match-p "-list\\.org\\'" name)))) (string-match-p "-list\\.org\\'" name))))
(defun z/read-org-title+mtime (file) ;; ── Metadata reader ───────────────────────────────────────────────────────────
"Return (TITLE . MTIME) for Org FILE.
TITLE from #+TITLE or file name. (defun z/read-org-meta (file)
MTIME is the file's modification time (real 'last updated')."
(with-temp-buffer
(insert-file-contents file)
(org-mode)
(let* ((props (org-collect-keywords '("TITLE")))
(title-cell (assoc "TITLE" props))
(title (or (and title-cell
(car (cdr title-cell)))
(file-name-base file)))
(mtime (nth 5 (file-attributes file))))
(cons title mtime))))
(defun z/read-org-title+date (file)
"Return (TITLE . TIME) for Org FILE. "Return (TITLE . TIME) for Org FILE.
TITLE: TITLE: from #+TITLE, or file-name-base when absent.
- from #+TITLE, or file-name if missing. TIME : from #+DATE (parsed as an Org time string) when present and
parseable; otherwise falls back to the file's modification time.
TIME: Using #+DATE ensures intentionally-dated content sorts by its
- from #+DATE if parseable as an org time string, canonical publication date rather than an accidental disk mtime."
- otherwise from file's modification time."
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert-file-contents file)
(org-mode) (org-mode)
(let* ((props (org-collect-keywords '("TITLE" "DATE"))) (let* ((props (org-collect-keywords '("TITLE" "DATE")))
;; TITLE (title (or (cadr (assoc "TITLE" props))
(title-cell (assoc "TITLE" props))
(title (or (and title-cell
(car (cdr title-cell)))
(file-name-base file))) (file-name-base file)))
;; DATE (date-str (cadr (assoc "DATE" props)))
(date-cell (assoc "DATE" props))
(date-str (and date-cell
(car (cdr date-cell))))
(time (or (and date-str (time (or (and date-str
(ignore-errors (ignore-errors
(org-time-string-to-time date-str))) (org-time-string-to-time date-str)))
(nth 5 (file-attributes file))))) (file-attribute-modification-time
(file-attributes file)))))
(cons title time)))) (cons title time))))
(defun z/generate-recently-updated-org (&optional n) ;; ── Generator ────────────────────────────────────────────────────────────────
"Generate recently-updated.org in `z-org-root`.
Lists top N most recently updated Org pages (defun z/generate-recently-updated-org (&optional n)
(excluding tags, sitemaps, *-list.org, etc). "Write home/recently-updated.org listing the top N recently updated files.
Defaults to N=30." N defaults to 30. Returns the number of entries written."
(let* ((count (or n 30)) (let* ((count (or n 30))
(org-files (directory-files-recursively z-org-root "\\.org\\'")) (org-root (file-name-as-directory z/site-root))
(all-files (directory-files-recursively org-root "\\.org\\'"))
(items '())) (items '()))
;; Collect (REL PATH, TITLE, TIME) ;; Collect (REL TITLE TIME)
(dolist (full org-files) (dolist (full all-files)
(let ((rel (file-relative-name full z-org-root))) (let ((rel (file-relative-name full org-root)))
(unless (z/recent-omit-org-p rel) (unless (z/recent-omit-org-p rel)
(pcase-let* ((`(,title . ,time) (z/read-org-title+mtime full))) (pcase-let ((`(,title . ,time) (z/read-org-meta full)))
(push (list rel title time) items))))) (push (list rel title time) items)))))
;; Sort newest first by TIME ;; Sort newest first
(setq items (setq items (sort items (lambda (a b) (time-less-p (nth 2 b) (nth 2 a)))))
(sort items ;; Trim to N
(lambda (a b)
(time-less-p (nth 2 b) (nth 2 a)))))
;; Trim
(setq items (cl-subseq items 0 (min count (length items)))) (setq items (cl-subseq items 0 (min count (length items))))
;; Write Org file ;; Write Org
(with-temp-file (site-path "home/recently-updated.org") (with-temp-file (site-path "home/recently-updated.org")
(insert "#+TITLE: Recently Updated\n" (insert "#+TITLE: Recently Updated\n"
"#+OPTIONS: toc:nil num:nil\n\n" "#+OPTIONS: toc:nil num:nil\n\n"
"* Recently Updated (top 26 files - per lima's request)\n") (format "* Recently Updated (top %d files)\n" (length items)))
(dolist (it items) (dolist (it items)
(let* ((rel (nth 0 it)) (let* ((rel (nth 0 it))
(title (nth 1 it)) (title (nth 1 it))
(time (nth 2 it)) (time (nth 2 it))
(datestr (format-time-string "%Y-%m-%d %H:%M" time))) (datestr (format-time-string "%Y-%m-%d %H:%M" time)))
(insert (format "- [[file:%s][%s]] @@html:<span class=\"post-date\">%s</span>@@\n" (insert (format "- [[file:%s][%s]] @@html:<span class=\"post-date\">%s</span>@@\n"
rel title datestr)))))) rel title datestr)))))
(message "Wrote recently-updated.org")) (length items)))
(provide 'recently-updated) (provide 'recently-updated)
;;; recently-updated.el ends here

View File

@@ -1,26 +1,40 @@
;;; sidenotes.el --- Sidenote / no-sidenotes helpers -*- lexical-binding: t; -*-
;;; Commentary:
;; Predicates for deciding whether a page should render with sidenotes.
;; Loaded by build-site.el via (require 'sidenotes).
;;
;; NOTE: Do NOT define `site-root' here. build-site.el owns that definition.
;;; Code:
(defun z/no-sidenotes-file-p (file) (defun z/no-sidenotes-file-p (file)
"Return non-nil if FILE should be rendered without sidenotes. "Return non-nil if FILE should be rendered without sidenotes.
A file is no-sidenotes if: A file suppresses sidenotes when any of the following is true:
- It has a #+NO_SIDENOTES: keyword, or - It has a #+NO_SIDENOTES: keyword with a non-empty value.
- Its FILETAGS contain :NO_SIDENOTES: or :KANBAN:, or - Its FILETAGS contain :NO_SIDENOTES: or :KANBAN:.
- Any top-level heading contains \"KANBAN\"." - Any top-level heading contains the word \"KANBAN\" (case-insensitive)."
(when (file-exists-p file) (when (file-exists-p file)
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert-file-contents file)
(org-mode) (org-mode)
(let* ((case-fold-search t) (let* ((case-fold-search t)
(keywords (org-collect-keywords (keywords (org-collect-keywords '("NO_SIDENOTES" "FILETAGS")))
'("NO_SIDENOTES" "FILETAGS")))
(flag (cadr (assoc "NO_SIDENOTES" keywords))) (flag (cadr (assoc "NO_SIDENOTES" keywords)))
(filetags (cadr (assoc "FILETAGS" keywords)))) (filetags (cadr (assoc "FILETAGS" keywords))))
(or (or
;; Explicit keyword present with any non-whitespace value
(and flag (string-match-p "\\S-" flag)) (and flag (string-match-p "\\S-" flag))
;; Tag-based suppression
(and filetags (and filetags
(string-match-p (string-match-p ":\\(NO_SIDENOTES\\|KANBAN\\):"
":\\(NO_SIDENOTES\\|KANBAN\\):"
(concat ":" filetags ":"))) (concat ":" filetags ":")))
;; Heading-based suppression
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(re-search-forward "^\\*+ .*KANBAN.*" nil t))))))) (re-search-forward "^\\*+ .*KANBAN.*" nil t)))))))
(provide 'sidenotes) (provide 'sidenotes)
;;; sidenotes.el ends here

View File

@@ -1,428 +1,268 @@
(defvar site-root ;;; sitemaps.el --- Sitemap generators for org-publish -*- lexical-binding: t; -*-
(file-name-directory
(or load-file-name buffer-file-name)))
(defun site-path (path) ;;; Commentary:
(expand-file-name path site-root)) ;; Custom :sitemap-function implementations for each publishing project.
;;
;; NOTE: Do NOT define `site-root' here. build-site.el owns that definition.
;;; Code:
(require 'cl-lib)
(require 'org)
;; ─────────────────────────────────────────────────────────────────────────────
;; Internal helpers
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/sitemap--tag-html (tags-raw)
"Convert a raw FILETAGS string into an Org-mode HTML inline tag list.
Returns an empty string when TAGS-RAW is nil or blank."
(if (and tags-raw (string-match-p "\\S-" tags-raw))
(mapconcat
(lambda (tag)
(format "@@html:<a href=\"/tags/%s.html\"><span class=\"post-tag\">%s</span></a>@@"
tag tag))
(split-string tags-raw ":" t)
" ")
""))
(defun z/sitemap--entry-data (link base-dir)
"Extract (FULL-PATH DATE-STR TAGS-STR) for a sitemap ENTRY under BASE-DIR.
LINK is the raw [[file:...][...]] string produced by org-publish."
(let* ((filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
(match-string 1 link)
link))
(full-path (expand-file-name filename base-dir))
(date (and (file-exists-p full-path)
(org-publish-find-date full-path org-publish-project-alist)))
(date-str (if date (format-time-string "%d-%m-%Y %H:%M" date) "no date"))
(tags-raw (and (file-exists-p full-path)
(with-temp-buffer
(insert-file-contents full-path)
(org-mode)
(cadr (assoc "FILETAGS"
(org-collect-keywords '("FILETAGS"))))))))
(list full-path date-str (z/sitemap--tag-html tags-raw) date)))
(defun z/sitemap--flat-list (title list base-dir section-title categories-rel)
"Render a flat bullet-point sitemap.
TITLE — org-publish title string
LIST — the raw list from org-publish (car is root node)
BASE-DIR — absolute path to the project's :base-directory
SECTION-TITLE — heading text, e.g. \"Posts\"
CATEGORIES-REL — relative path to categories.html from this project root"
(concat
"#+TITLE: " title "\n"
"#+OPTIONS: toc:nil num:nil\n\n"
(format "See the categories: @@html:<a href=\"%s\">Categories</a>@@\n\n" categories-rel)
"* " section-title "\n"
(mapconcat
(lambda (entry)
(when (consp entry)
(let* ((link (car entry))
(data (z/sitemap--entry-data link base-dir))
(date-str (nth 1 data))
(tags-str (nth 2 data)))
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s"
link date-str tags-str))))
(cdr list)
"\n")))
;; ─────────────────────────────────────────────────────────────────────────────
;; Posts
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/posts-sitemap (title list) (defun z/posts-sitemap (title list)
"sitemap that lists post links as bullet points with dates and tags." "Flat sitemap for org-posts."
(concat (z/sitemap--flat-list title list
"#+TITLE: " title "\n" (site-path "posts/")
"#+OPTIONS: toc:nil num:nil \n\n" "Posts:"
"See the categories: @@html:<a href=\"../home/categories.html\">Categories</a>@@\n\n" "../home/categories.html"))
"* Posts:\n"
(mapconcat
(lambda (entry)
(let* ((link (car entry))
;; extract relative file name from the link
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
(match-string 1 link)
link))
(full-path (expand-file-name filename (site-path "posts/")))
(date-str "no date")
(tags-str ""))
;; Get publish date
(let ((date (org-publish-find-date full-path org-publish-project-alist)))
(when date
(setq date-str (format-time-string "%d-%m-%Y %H:%M" date))))
;; Get FILETAGS from file buffer
(when (file-exists-p full-path)
(with-temp-buffer
(insert-file-contents full-path)
(org-mode)
(let* ((tags (cadr (assoc "FILETAGS" (org-collect-keywords '("FILETAGS"))))))
(when tags
(setq tags-str (mapconcat (lambda (tag)
(format "@@html:<a href=\"/tags/%s.html\"> <span class=\"post-tag\">%s</span> </a>@@" tag tag))
(split-string tags ":" t) ;; <- Splits by ":" and removes empty strings
" "))))))
;; Final line output
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s" link date-str tags-str)))
(cdr list)
"\n")))
;; ─────────────────────────────────────────────────────────────────────────────
;; Blogs — flat (kept for compatibility, not used as default)
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/blogs-sitemap (title list) (defun z/blogs-sitemap (title list)
"sitemap that lists blog links as bullet points with dates and tags." "Flat sitemap for org-blogs (use z/blogs-grouped-sitemap for the default)."
(concat (z/sitemap--flat-list title list
"#+TITLE: " title "\n" (site-path "blogs/")
"#+OPTIONS: toc:nil num:nil \n\n" "Blogs:"
"See the categories: @@html:<a href=\"../home/categories.html\">Categories</a>@@\n\n" "../home/categories.html"))
"* Blogs:\n"
(mapconcat
(lambda (entry)
(let* ((link (car entry))
;; extract relative file name from the link
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
(match-string 1 link)
link))
(full-path (expand-file-name filename (site-path "blogs/")))
(date-str "no date")
(tags-str ""))
;; Get publish date
(let ((date (org-publish-find-date full-path org-publish-project-alist)))
(when date
(setq date-str (format-time-string "%d-%m-%Y %H:%M" date))))
;; Get FILETAGS from file buffer
(when (file-exists-p full-path)
(with-temp-buffer
(insert-file-contents full-path)
(org-mode)
(let* ((tags (cadr (assoc "FILETAGS" (org-collect-keywords '("FILETAGS"))))))
(when tags
(setq tags-str (mapconcat (lambda (tag)
(format "@@html:<a href=\"/tags/%s.html\"> <span class=\"post-tag\">%s</span> </a>@@" tag tag))
(split-string tags ":" t) ;; <- Splits by ":" and removes empty strings
" "))))))
;; Final line output
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s" link date-str tags-str)))
(cdr list)
"\n")))
;; ─────────────────────────────────────────────────────────────────────────────
;; Blogs — grouped by year → month
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/blogs-grouped-sitemap (title list) (defun z/blogs-grouped-sitemap (title list)
"Sitemap grouped by year and month with dates and FILETAGS." "Sitemap for org-blogs grouped by year and month, newest first."
(let ((data (make-hash-table :test 'equal))) (let ((data (make-hash-table :test 'equal)))
;; STEP 1: Collect entries into (year -> month -> entries) ;; Collect into year-key → month-key → list of (link date-str tags-str time)
(dolist (entry (cdr list)) (dolist (entry (cdr list))
(when (consp entry) (when (consp entry)
(let* ((link (car entry)) (let* ((link (car entry))
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link) (ed (z/sitemap--entry-data link (site-path "blogs/")))
(match-string 1 link) (full-path (nth 0 ed))
link)) (date-str (nth 1 ed))
(full-path (expand-file-name filename (site-path "blogs/"))) (tags-str (nth 2 ed))
(date (when (file-exists-p full-path) (time (nth 3 ed)))
(org-publish-find-date full-path org-publish-project-alist)))) (when time
(let* ((year (format-time-string "%Y" time))
(when date (month (format-time-string "%B %Y" time))
(let* ((year (format-time-string "%Y" date)) (year-table (or (gethash year data)
(month (format-time-string "%B %Y" date))
(date-str (format-time-string "%d-%m-%Y %H:%M" date))
(tags-str ""))
;; Get tags
(when (file-exists-p full-path)
(with-temp-buffer
(insert-file-contents full-path)
(org-mode)
(let ((tags (cadr (assoc "FILETAGS"
(org-collect-keywords '("FILETAGS"))))))
(when tags
(setq tags-str
(mapconcat
(lambda (tag)
(format "@@html:<a href=\"/tags/%s.html\"> \
<span class=\"post-tag\">%s</span> </a>@@" tag tag))
(split-string tags ":" t)
" "))))))
;; Insert into hash table
(let ((year-table (or (gethash year data)
(puthash year (make-hash-table :test 'equal) data)))) (puthash year (make-hash-table :test 'equal) data))))
(let ((month-list (gethash month year-table)))
(puthash month (puthash month
(cons (list link date-str tags-str date) (cons (list link date-str tags-str time)
month-list) (gethash month year-table))
year-table)))))))) year-table))))))
;; STEP 2: Render output ;; Render
(let ((output (concat (let ((output (concat "#+TITLE: " title "\n"
"#+TITLE: " title "\n"
"#+OPTIONS: toc:nil num:nil\n\n" "#+OPTIONS: toc:nil num:nil\n\n"
"See the categories: @@html:<a href=\"../home/categories.html\">Categories</a>@@\n\n"))) "See the categories: @@html:<a href=\"../home/categories.html\">Categories</a>@@\n\n")))
;; Sort years descending
(dolist (year (sort (hash-table-keys data) #'string>)) (dolist (year (sort (hash-table-keys data) #'string>))
(setq output (concat output "* " year "\n")) (setq output (concat output "* " year "\n"))
(let ((year-table (gethash year data))) (let ((year-table (gethash year data)))
(dolist (month (sort (hash-table-keys year-table)
;; Sort months by actual date (descending)
(dolist (month
(sort (hash-table-keys year-table)
(lambda (a b) (lambda (a b)
(time-less-p (time-less-p
(date-to-time (concat "01 " b)) (date-to-time (concat "01 " b))
(date-to-time (concat "01 " a)))))) (date-to-time (concat "01 " a))))))
(setq output (concat output "\n** " month "\n")) (setq output (concat output "\n** " month "\n"))
(dolist (entry (sort (gethash month year-table)
;; Sort entries by date descending
(dolist (entry
(sort (gethash month year-table)
(lambda (a b) (lambda (a b)
(time-less-p (nth 3 b) (nth 3 a))))) (time-less-p (nth 3 b) (nth 3 a)))))
(let ((link (nth 0 entry))
(date-str (nth 1 entry))
(tags-str (nth 2 entry)))
(setq output (setq output
(concat output (concat output
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s\n" (format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s\n"
link date-str tags-str)))))))) (nth 0 entry)
(nth 1 entry)
(nth 2 entry))))))))
output))) output)))
;; ─────────────────────────────────────────────────────────────────────────────
;; Books
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/books-sitemap (title list) (defun z/books-sitemap (title list)
"sitemap that lists books." "Flat sitemap for org-books."
(concat (z/sitemap--flat-list title list
"#+TITLE: " title "\n" (site-path "books/")
"Book Notes:"
"../home/categories.html"))
;; ─────────────────────────────────────────────────────────────────────────────
;; Year-scoped sitemaps (generic helper)
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/year-grouped-sitemap (title list year base-dir categories-rel)
"Generic year-scoped, month-grouped sitemap.
YEAR is a string like \"2025\". BASE-DIR is the project root.
CATEGORIES-REL is the relative href to categories.html."
(let ((output (concat "#+TITLE: " title "\n"
"#+OPTIONS: toc:nil num:nil\n\n" "#+OPTIONS: toc:nil num:nil\n\n"
"See the categories: @@html:<a href=\"../home/categories.html\">Categories</a>@@\n\n" (format "See the categories: @@html:<a href=\"%s\">Categories</a>@@\n\n"
"* Book Notes:\n" categories-rel)
(mapconcat "* " year "\n"))
(lambda (entry) (current-month nil))
(dolist (entry (cdr list))
(when (consp entry)
(let* ((link (car entry)) (let* ((link (car entry))
;; extract relative file name from the link (ed (z/sitemap--entry-data link base-dir))
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link) (date-str (nth 1 ed))
(match-string 1 link) (tags-str (nth 2 ed))
link)) (time (nth 3 ed))
(full-path (expand-file-name filename (site-path "books/"))) (month-str (if time (format-time-string "%B %Y" time) "No date")))
(date-str "no date") (unless (equal month-str current-month)
(tags-str "")) (setq current-month month-str)
;; Get publish date (setq output (concat output "\n** " month-str "\n")))
(let ((date (org-publish-find-date full-path org-publish-project-alist))) (setq output
(when date (concat output
(setq date-str (format-time-string "%d-%m-%Y %H:%M" date)))) (format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s\n"
;; Get FILETAGS from file buffer link date-str tags-str))))))
(when (file-exists-p full-path) output))
(with-temp-buffer
(insert-file-contents full-path)
(org-mode)
(let* ((tags (cadr (assoc "FILETAGS" (org-collect-keywords '("FILETAGS"))))))
(when tags
(setq tags-str (mapconcat (lambda (tag)
(format "@@html:<a href=\"/tags/%s.html\"> <span class=\"post-tag\">%s</span> </a>@@" tag tag))
(split-string tags ":" t) ;; <- Splits by ":" and removes empty strings
" "))))))
;; Final line output
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s" link date-str tags-str)))
(cdr list)
"\n")))
(defun z/2025-sitemap (title list) (defun z/2025-sitemap (title list)
"Sitemap that lists 2025 posts grouped by month, with dates and FILETAGS." "Sitemap for blogs/2025/ grouped by month."
(let ((output (concat (z/year-grouped-sitemap title list "2025"
"#+TITLE: " title "\n" (site-path "blogs/2025/")
"#+OPTIONS: toc:nil num:nil \n\n" "../../home/categories.html"))
"See the categories: @@html:<a href=\"../../home/categories.html\">Categories</a>@@\n\n"
"* 2025\n"))
(current-month nil))
;; `list` is what org-publish passes in; we skip its car (top-level title node)
(dolist (entry (cdr list))
;; In this setup each ENTRY is usually (LINK . OTHER-STUFF)
(when (consp entry)
(let* ((link (car entry))
;; Extract relative filename from the [[file:...][...]] link
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
(match-string 1 link)
link))
(full-path (expand-file-name filename (site-path "blogs/2025/")))
(date (when (file-exists-p full-path)
(org-publish-find-date full-path org-publish-project-alist)))
(date-str (if date
(format-time-string "%d-%m-%Y %H:%M" date)
"no date"))
(month-str (if date
(format-time-string "%B %Y" date) ; e.g. "August 2025"
"No date"))
(tags-str ""))
;; Collect FILETAGS from the file
(when (file-exists-p full-path)
(with-temp-buffer
(insert-file-contents full-path)
(org-mode)
(let ((tags (cadr (assoc "FILETAGS"
(org-collect-keywords '("FILETAGS"))))))
(when tags
(setq tags-str
(mapconcat
(lambda (tag)
(format "@@html:<a href=\"/tags/%s.html\"> \
<span class=\"post-tag\">%s</span> </a>@@" tag tag))
(split-string tags ":" t)
" "))))))
;; Insert month heading whenever month changes
(unless (equal month-str current-month)
(setq current-month month-str)
(setq output (concat output "\n** " month-str "\n")))
;; Insert the actual entry
(setq output
(concat output
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s\n"
link date-str tags-str))))))
output))
(defun z/2026-sitemap (title list) (defun z/2026-sitemap (title list)
"Sitemap that lists 2026 blogs grouped by month, with dates and FILETAGS." "Sitemap for blogs/2026/ grouped by month."
(let ((output (concat (z/year-grouped-sitemap title list "2026"
"#+TITLE: " title "\n" (site-path "blogs/2026/")
"#+OPTIONS: toc:nil num:nil \n\n" "../../home/categories.html"))
"See the categories: @@html:<a href=\"../../home/categories.html\">Categories</a>@@\n\n"
"* 2026\n"))
(current-month nil))
(dolist (entry (cdr list))
(when (consp entry)
(let* ((link (car entry))
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
(match-string 1 link)
link))
(full-path (expand-file-name filename (site-path "blogs/2026/")))
(date (when (file-exists-p full-path)
(org-publish-find-date full-path org-publish-project-alist)))
(date-str (if date
(format-time-string "%d-%m-%Y %H:%M" date)
"no date"))
(month-str (if date
(format-time-string "%B %Y" date)
"No date"))
(tags-str ""))
(when (file-exists-p full-path)
(with-temp-buffer
(insert-file-contents full-path)
(org-mode)
(let ((tags (cadr (assoc "FILETAGS"
(org-collect-keywords '("FILETAGS"))))))
(when tags
(setq tags-str
(mapconcat
(lambda (tag)
(format "@@html:<a href=\"/tags/%s.html\"> \
<span class=\"post-tag\">%s</span> </a>@@" tag tag))
(split-string tags ":" t)
" "))))))
(unless (equal month-str current-month)
(setq current-month month-str)
(setq output (concat output "\n** " month-str "\n")))
(setq output
(concat output
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s\n"
link date-str tags-str))))))
output))
;; ─────────────────────────────────────────────────────────────────────────────
;; Career
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/career-sitemap (title list) (defun z/career-sitemap (title list)
"Sitemap that lists careers posts grouped by month, with dates and FILETAGS." "Sitemap for posts/career/ grouped by month."
(let ((output (concat (concat
"#+TITLE: " title "\n" (z/year-grouped-sitemap title list ""
"#+OPTIONS: toc:nil num:nil \n\n" (site-path "posts/career/")
"See the categories: @@html:<a href=\"../../home/categories.html\">Categories</a>@@\n\n" "../../home/categories.html")
"See the following page for more details: @@html:<a href=\"./career-intro.html\">Career Intro</a>@@\n" "\nSee the following page for more details: @@html:<a href=\"./career-intro.html\">Career Intro</a>@@\n"))
))
(current-month nil))
(dolist (entry (cdr list))
(when (consp entry)
(let* ((link (car entry))
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
(match-string 1 link)
link))
(full-path (expand-file-name filename (site-path "posts/career/")))
(date (when (file-exists-p full-path)
(org-publish-find-date full-path org-publish-project-alist)))
(date-str (if date
(format-time-string "%d-%m-%Y %H:%M" date)
"no date"))
(month-str (if date
(format-time-string "%B %Y" date) ; e.g. "August 2025"
"No date"))
(tags-str ""))
(when (file-exists-p full-path)
(with-temp-buffer
(insert-file-contents full-path)
(org-mode)
(let ((tags (cadr (assoc "FILETAGS"
(org-collect-keywords '("FILETAGS"))))))
(when tags
(setq tags-str
(mapconcat
(lambda (tag)
(format "@@html:<a href=\"/tags/%s.html\"> \
<span class=\"post-tag\">%s</span> </a>@@" tag tag))
(split-string tags ":" t)
" "))))))
;; Insert month heading whenever month changes
(unless (equal month-str current-month)
(setq current-month month-str)
(setq output (concat output "\n** " month-str "\n")))
(setq output
(concat output
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s\n"
link date-str tags-str))))))
output))
;; ─────────────────────────────────────────────────────────────────────────────
;; Categories
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/categories-sitemap (title _list) (defun z/categories-sitemap (title _list)
"Generate a categories page by scanning tags across org-posts and org-blogs." "Generate a categories overview by scanning tags across posts and blogs."
(let* ((expanded (org-publish-expand-projects org-publish-project-alist)) (let* ((expanded (org-publish-expand-projects org-publish-project-alist))
(posts (assoc "org-posts" expanded)) (posts (assoc "org-posts" expanded))
(blogs (assoc "org-blogs" expanded)) (blogs (assoc "org-blogs" expanded))
;; DO NOT set :exclude to "" — it excludes everything
(files (cl-remove-duplicates
(append (and posts (org-publish-get-base-files posts))
(and blogs (org-publish-get-base-files blogs)))
:test #'file-equal-p))
;; optional: drop the generated sitemaps
(files (cl-remove-if (files (cl-remove-if
(lambda (f) (lambda (f)
(member (file-name-nondirectory f) (member (file-name-nondirectory f)
'("posts-list.org" "blogs-list.org" "sitemap.org" "categories.org"))) '("posts-list.org" "blogs-list.org"
files)) "sitemap.org" "categories.org")))
(cl-remove-duplicates
(append (and posts (org-publish-get-base-files posts))
(and blogs (org-publish-get-base-files blogs)))
:test #'file-equal-p)))
(counts (make-hash-table :test 'equal))) (counts (make-hash-table :test 'equal)))
;;(message "files I will scan: %S" files)
(dolist (f files) (dolist (f files)
(when (file-readable-p f) (when (file-readable-p f)
(with-temp-buffer (with-temp-buffer
(insert-file-contents f) (insert-file-contents f)
(org-mode) (org-mode)
(let* ((kw (org-collect-keywords '("FILETAGS" "TAGS"))) (let* ((kw (org-collect-keywords '("FILETAGS" "TAGS")))
(raw (car (or (cdr (assoc "FILETAGS" kw)) (raw (cadr (or (assoc "FILETAGS" kw)
(cdr (assoc "TAGS" kw)))))) (assoc "TAGS" kw)))))
(when raw (when raw
(dolist (tag (split-string raw ":" t)) (dolist (tag (split-string raw ":" t))
(puthash tag (1+ (gethash tag counts 0)) counts))))))) (puthash tag (1+ (gethash tag counts 0)) counts)))))))
(let (tags) (let (tags)
(maphash (lambda (k _) (push k tags)) counts) (maphash (lambda (k _) (push k tags)) counts)
(setq tags (sort tags #'string-lessp)) (setq tags (sort tags #'string-lessp))
(concat (concat
"#+TITLE: " title "\n#+OPTIONS: toc:nil num:nil title:nil\n\n* Categories (Includes both blogs and posts)\n" "#+TITLE: " title "\n#+OPTIONS: toc:nil num:nil title:nil\n\n"
"* Categories (Includes both blogs and posts)\n"
(if tags (if tags
(mapconcat (mapconcat
(lambda (tag) (lambda (tag)
(format "- [[file:../tags/%s.org][@@html:<span class=\"post-tag\">%s</span>@@]] (%d)" (format "- [[file:../tags/%s.org][@@html:<span class=\"post-tag\">%s</span>@@]] (%d)"
(z/tag-slug tag) tag (gethash tag counts)) (z/tag-slug tag) tag (gethash tag counts)))
)
tags tags
"\n") "\n")
"_No tags found yet._"))))) "_No tags found yet._")))))
;; ─────────────────────────────────────────────────────────────────────────────
;; WIP sitemap
;; ─────────────────────────────────────────────────────────────────────────────
(defun z/wip-file-p (file) (defun z/wip-file-p (file)
"Return non-nil if FILE should be treated as WIP. "Return non-nil if FILE is marked as work-in-progress.
A file is WIP if:
- It has a #+WIP: keyword with any non-empty value, or A file is WIP when any of the following is true:
- Its FILETAGS contain :WIP:, or - It has a #+WIP: keyword with a non-empty value.
- Any top-level heading contains the string \"WIP\" (case-insensitive)." - Its FILETAGS contain :WIP:.
- Any top-level heading contains \"WIP\" (case-insensitive)."
(when (file-exists-p file) (when (file-exists-p file)
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert-file-contents file)
@@ -433,18 +273,15 @@ A file is WIP if:
(filetags (cadr (assoc "FILETAGS" keywords)))) (filetags (cadr (assoc "FILETAGS" keywords))))
(or (or
(and wip (string-match-p "\\S-" wip)) (and wip (string-match-p "\\S-" wip))
(and filetags (and filetags (string-match-p ":WIP:" (concat ":" filetags ":")))
(string-match-p ":WIP:" (concat ":" filetags ":")))
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(re-search-forward "^\\*+ .*WIP.*" nil t))))))) (re-search-forward "^\\*+ .*WIP.*" nil t)))))))
(defun z/wip-sitemap (title list) (defun z/wip-sitemap (title list)
"Sitemap that lists only entries whose source files are WIP." "Sitemap listing only entries whose source files are marked WIP."
(let* ((items (let ((items
(delq (delq nil
nil
(mapcar (mapcar
(lambda (entry) (lambda (entry)
(when (consp entry) (when (consp entry)
@@ -452,7 +289,7 @@ A file is WIP if:
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link) (filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
(match-string 1 link) (match-string 1 link)
link)) link))
(full-path (expand-file-name filename site-root))) (full-path (expand-file-name filename z/site-root)))
(when (z/wip-file-p full-path) (when (z/wip-file-p full-path)
(let* ((date (org-publish-find-date full-path org-publish-project-alist)) (let* ((date (org-publish-find-date full-path org-publish-project-alist))
(date-str (if date (date-str (if date
@@ -460,14 +297,14 @@ A file is WIP if:
""))) "")))
(format "- %s @@html:<span class=\"post-date\">%s</span>@@" (format "- %s @@html:<span class=\"post-date\">%s</span>@@"
link date-str)))))) link date-str))))))
(cdr list))))) ;; skip sitemap root (cdr list)))))
(concat (concat "#+TITLE: " title "\n"
"#+TITLE: " title "\n"
"#+OPTIONS: toc:nil num:nil\n\n" "#+OPTIONS: toc:nil num:nil\n\n"
"* Work in progress\n" "* Work in progress\n"
(if items (if items
(mapconcat #'identity items "\n") (mapconcat #'identity items "\n")
"No items currently marked as WIP.\n")))) "No items currently marked as WIP.\n"))))
(provide 'sitemaps) (provide 'sitemaps)
;;; sitemaps.el ends here

View File

@@ -1,10 +1,26 @@
;;; tags.el --- Tag index and HTML helpers -*- lexical-binding: t; -*-
;;; Commentary:
;; Collects FILETAGS from posts/blogs, generates tags/*.org pages, and
;; injects tag HTML into exported pages.
;;
;; NOTE: Do NOT define `site-root' here. build-site.el owns that definition.
;;; Code:
(require 'cl-lib)
(require 'org)
;; ── Slug ─────────────────────────────────────────────────────────────────────
(defun z/tag-slug (s) (defun z/tag-slug (s)
"Turn a tag into a safe filename." "Return a URL-safe filename slug for tag S."
(let ((down (downcase s))) (replace-regexp-in-string "[^a-z0-9]+" "-" (downcase s)))
(replace-regexp-in-string "[^a-z0-9]+" "-" down)))
;; ── File collection ───────────────────────────────────────────────────────────
(defun z/collect-post-files () (defun z/collect-post-files ()
"Return all .org files from org-posts and org-blogs." "Return all .org source files from the org-posts and org-blogs projects."
(let* ((expanded (org-publish-expand-projects org-publish-project-alist)) (let* ((expanded (org-publish-expand-projects org-publish-project-alist))
(posts (assoc "org-posts" expanded)) (posts (assoc "org-posts" expanded))
(blogs (assoc "org-blogs" expanded))) (blogs (assoc "org-blogs" expanded)))
@@ -13,36 +29,44 @@
(and blogs (org-publish-get-base-files blogs))) (and blogs (org-publish-get-base-files blogs)))
:test #'file-equal-p))) :test #'file-equal-p)))
;; ── Tag index ─────────────────────────────────────────────────────────────────
(defconst z/generated-org-names
'("posts-list.org" "blogs-list.org" "sitemap.org" "categories.org"
"recently-updated.org" "wip.org")
"Generated Org files that should never be indexed for tags.")
(defun z/gather-tag-index () (defun z/gather-tag-index ()
"Return hash: tag -> list of (FILE TITLE DATE-ISO)." "Return a hash-table mapping tag -> list of (FILE TITLE DATE-ISO)."
(let ((idx (make-hash-table :test 'equal))) (let ((idx (make-hash-table :test 'equal)))
(dolist (f (z/collect-post-files)) (dolist (f (z/collect-post-files))
(when (and (string-match-p "\\.org\\'" f) (when (and (string-match-p "\\.org\\'" f)
(file-readable-p f) (file-readable-p f)
;; ignore generated lists
(not (member (file-name-nondirectory f) (not (member (file-name-nondirectory f)
'("posts-list.org" "blogs-list.org" "sitemap.org" "categories.org")))) z/generated-org-names)))
(with-temp-buffer (with-temp-buffer
(insert-file-contents f) (insert-file-contents f)
(org-mode) (org-mode)
(let* ((kw (org-collect-keywords '("TITLE" "FILETAGS" "TAGS" "DATE"))) (let* ((kw (org-collect-keywords '("TITLE" "FILETAGS" "TAGS" "DATE")))
(title (or (car (cdr (assoc "TITLE" kw))) (title (or (cadr (assoc "TITLE" kw)) (file-name-base f)))
(file-name-base f))) (date (or (cadr (assoc "DATE" kw)) ""))
(date (or (car (cdr (assoc "DATE" kw))) "")) ;; optional (raw (cadr (or (assoc "FILETAGS" kw)
(raw (car (or (cdr (assoc "FILETAGS" kw)) (assoc "TAGS" kw)))))
(cdr (assoc "TAGS" kw))))))
(when raw (when raw
(dolist (tag (split-string raw ":" t)) (dolist (tag (split-string raw ":" t))
(push (list f title date) (gethash tag idx)))))))) (push (list f title date) (gethash tag idx))))))))
idx)) idx))
;; ── Tag page writer ───────────────────────────────────────────────────────────
(defun z/write-tag-pages () (defun z/write-tag-pages ()
"Generate tags/*.org pages listing posts for each tag." "Generate tags/*.org pages, one per tag.
(let* ((site-root (expand-file-name "~/master-folder/org_files/org_web/")) Returns the number of tag pages written."
(tags-dir (expand-file-name "tags" site-root))) (let* ((tags-dir (site-path "tags/"))
(idx (z/gather-tag-index))
(count 0))
(unless (file-directory-p tags-dir) (unless (file-directory-p tags-dir)
(make-directory tags-dir t)) (make-directory tags-dir t))
(let ((idx (z/gather-tag-index)))
(maphash (maphash
(lambda (tag items) (lambda (tag items)
(let* ((slug (z/tag-slug tag)) (let* ((slug (z/tag-slug tag))
@@ -50,29 +74,34 @@
(with-temp-file outfile (with-temp-file outfile
(insert (format "#+TITLE: Tag: %s\n#+OPTIONS: toc:nil num:nil title:nil\n\n* Posts tagged %s\n" (insert (format "#+TITLE: Tag: %s\n#+OPTIONS: toc:nil num:nil title:nil\n\n* Posts tagged %s\n"
tag tag)) tag tag))
;; sort newest first if DATE present ;; Sort newest first
(setq items (sort items (lambda (a b) (string> (nth 2 a) (nth 2 b))))) (setq items (sort items (lambda (a b) (string> (nth 2 a) (nth 2 b)))))
(dolist (it items) (dolist (it items)
(let* ((file (nth 0 it)) (let* ((file (nth 0 it))
(title (nth 1 it)) (title (nth 1 it))
(rel (file-relative-name file tags-dir))) (rel (file-relative-name file tags-dir)))
;; link to the source .org; org-publish will rewrite to the .html (insert (format "- [[file:%s][%s]]\n" rel title)))))
(insert (format "- [[file:%s][%s]]\n" rel title))))))) (cl-incf count)))
idx) idx)
))) count))
;; ── HTML tag rendering ────────────────────────────────────────────────────────
(defun z/filetags-html (info) (defun z/filetags-html (info)
"Return an HTML snippet for FILETAGS from INFO, or nil if none." "Return an HTML <div class=\"filetags\"> snippet from export INFO, or nil."
(let ((tags (plist-get info :filetags))) (let ((tags (plist-get info :filetags)))
(when tags (when tags
(format (format
"<div class=\"filetags\">%s</div>\n" "<div class=\"filetags\">%s</div>\n"
(mapconcat (lambda (tag) (mapconcat
(format "<a href=\"/home/categories.html\"> <span class=\"post-tag\">%s</span> </a>" tag)) (lambda (tag)
tags " "))))) (format "<a href=\"/home/categories.html\"><span class=\"post-tag\">%s</span></a>"
tag))
tags
" ")))))
(defun z/insert-filetags-after-title (output backend info) (defun z/insert-filetags-after-title (output backend info)
"Insert FILETAGS after the first <h1 class=\"title\"> in OUTPUT." "Insert FILETAGS HTML after the first <h1 class=\"title\"> in OUTPUT."
(if (org-export-derived-backend-p backend 'html) (if (org-export-derived-backend-p backend 'html)
(let ((block (z/filetags-html info))) (let ((block (z/filetags-html info)))
(if (and block (if (and block
@@ -81,5 +110,6 @@
output)) output))
output)) output))
(provide 'tags) (provide 'tags)
;;; tags.el ends here

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
See the categories: @@html:<a href="../../home/categories.html">Categories</a>@@ See the categories: @@html:<a href="../../home/categories.html">Categories</a>@@
See the following page for more details: @@html:<a href="./career-intro.html">Career Intro</a>@@ *
** March 2026 ** March 2026
- [[file:ha-dr.org][High Availability, Disaster Recovery and Business Continuity]] @@html:<span class="post-date">11-03-2026 17:18</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@ - [[file:ha-dr.org][High Availability, Disaster Recovery and Business Continuity]] @@html:<span class="post-date">11-03-2026 17:18</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@
@@ -34,3 +34,5 @@ See the following page for more details: @@html:<a href="./career-intro.html">Ca
** October 2025 ** October 2025
- [[file:owasp.org][OWASP Top Ten]] @@html:<span class="post-date">19-10-2025 13:21</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@ - [[file:owasp.org][OWASP Top Ten]] @@html:<span class="post-date">19-10-2025 13:21</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@
- [[file:solid-principles.org][SOLID Principles]] @@html:<span class="post-date">18-10-2025 19:14</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@ - [[file:solid-principles.org][SOLID Principles]] @@html:<span class="post-date">18-10-2025 19:14</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@
See the following page for more details: @@html:<a href="./career-intro.html">Career Intro</a>@@

View File

@@ -4,7 +4,7 @@
See the categories: @@html:<a href="../home/categories.html">Categories</a>@@ See the categories: @@html:<a href="../home/categories.html">Categories</a>@@
* Posts: * Posts:
- [[file:career/career-list.org][Career List]] @@html:<span class="post-date">19-03-2026 16:17</span>@@ - [[file:career/career-list.org][Career List]] @@html:<span class="post-date">20-03-2026 23:53</span>@@
- [[file:career/ha-dr.org][High Availability, Disaster Recovery and Business Continuity]] @@html:<span class="post-date">11-03-2026 17:18</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@ - [[file:career/ha-dr.org][High Availability, Disaster Recovery and Business Continuity]] @@html:<span class="post-date">11-03-2026 17:18</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@
- [[file:career/javascript.org][Understands the Javascript language]] @@html:<span class="post-date">11-03-2026 16:52</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@ - [[file:career/javascript.org][Understands the Javascript language]] @@html:<span class="post-date">11-03-2026 16:52</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@
- [[file:career/restful-api.org][Restful API]] @@html:<span class="post-date">15-02-2026 23:00</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@ - [[file:career/restful-api.org][Restful API]] @@html:<span class="post-date">15-02-2026 23:00</span>@@ @@html:<a href="/tags/learning.html"><span class="post-tag">learning</span></a>@@ @@html:<a href="/tags/notes.html"><span class="post-tag">notes</span></a>@@

View File

@@ -40,13 +40,13 @@
- [[file:tags/learning.org][Tag: learning]] - [[file:tags/learning.org][Tag: learning]]
- [[file:tags/notes.org][Tag: notes]] - [[file:tags/notes.org][Tag: notes]]
- [[file:tags/review.org][Tag: review]] - [[file:tags/review.org][Tag: review]]
- [[file:tags/insights.org][Tag: insights]]
- [[file:tags/life.org][Tag: life]] - [[file:tags/life.org][Tag: life]]
- [[file:tags/website.org][Tag: website]] - [[file:tags/website.org][Tag: website]]
- [[file:tags/emacs.org][Tag: emacs]]
- [[file:tags/education.org][Tag: education]] - [[file:tags/education.org][Tag: education]]
- [[file:tags/reading.org][Tag: reading]] - [[file:tags/insights.org][Tag: insights]]
- [[file:tags/emacs.org][Tag: emacs]]
- [[file:tags/maths.org][Tag: maths]] - [[file:tags/maths.org][Tag: maths]]
- [[file:tags/reading.org][Tag: reading]]
- home - home
- [[file:home/countdown.org][Countdown]] - [[file:home/countdown.org][Countdown]]
- [[file:home/contact.org][Contact]] - [[file:home/contact.org][Contact]]