;;; build-html.el --- HTML export customisation -*- lexical-binding: t; -*-
;;; Code:
(require 'org)
(require 'ox-html)
(require 'subr-x)
(require 'tags)
(require 'sidenotes)
(require 'build-comments)
(setq org-export-global-macros
(append
org-export-global-macros
'(("sidenote"
. "@@html:\
\
$2@@")
("epigraph"
. "@@html:
@@")
("epigraph_single"
. "@@html:@@")
("epigraph3"
. "@@html:@@")
("kbd"
. "@@html:$1@@@@latex:\\texttt{$1}@@")
("margimg"
. "@@html:@@")
("countdown"
. "@@html:@@"))))
(defvar z/preamble
"
Updated: %C
")
(defvar z/postamble
"")
(defun z/org-html-src-block-mermaid (orig-fun src-block contents info)
"Export Mermaid source blocks as Mermaid divs."
(let ((lang (org-element-property :language src-block)))
(if (string= lang "mermaid")
(let ((code (org-remove-indentation
(org-element-property :value src-block))))
(format "\n%s\n
" code))
(funcall orig-fun src-block contents info))))
(advice-add 'org-html-src-block :around #'z/org-html-src-block-mermaid)
(defun z/org-html-add-body-classes (output backend info)
"Add layout-related classes to based on file metadata."
(if (and (org-export-derived-backend-p backend 'html)
(not (and (fboundp 'z/rpg-standalone-file-p)
(z/rpg-standalone-file-p info))))
(let* ((input-file (plist-get info :input-file))
(classes
(delq nil
(list
(when (and input-file (z/no-sidenotes-file-p input-file))
"no-sidenotes")))))
(if classes
(replace-regexp-in-string
"]*\\)>"
(format ""
(string-join classes " "))
output)
output))
output))
(add-to-list 'org-export-filter-final-output-functions
#'z/org-html-add-body-classes)
(add-to-list 'org-export-filter-body-functions
#'z/org-html-insert-comments-into-body)
(org-export-define-derived-backend 'z-html 'html
:filters-alist '((:filter-final-output . z/insert-filetags-after-title)))
(defun z/z-publish-to-html (plist filename pub-dir)
"Publish FILENAME to HTML using the z-html backend."
(org-publish-org-to 'z-html filename ".html" plist pub-dir))
(provide 'build-html)
;;; build-html.el ends here