diff options
Diffstat (limited to 'site/posts/cleopatra/org.org')
-rw-r--r-- | site/posts/cleopatra/org.org | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/site/posts/cleopatra/org.org b/site/posts/cleopatra/org.org new file mode 100644 index 0000000..9f5a77c --- /dev/null +++ b/site/posts/cleopatra/org.org @@ -0,0 +1,144 @@ +#+TITLE: Authoring Content with ~org-mode~ + +#+SERIES: ../cleopatra.html +#+SERIES_PREV: ./coq.html +#+SERIES_NEXT: ./literate-programming.html + +#+BEGIN_EXPORT html +<nav id="generate-toc"></nav> +<div id="history">site/cleopatra/org.org</div> +#+END_EXPORT + +* Author Guidelines + +* Implementation + +#+begin_src makefile :tangle org.mk +EMACS := cleopatra-emacs + +ORG_IN := $(shell find site/ -name "*.org") +ORG_OUT := $(ORG_IN:.org=.html) + +org-prebuild : .emacs +org-build : ${ORG_OUT} + +soupault-build : org-build + +ARTIFACTS += ${ORG_OUT} +CONFIGURE += .emacs + +EXPORT := --batch \ + --load="${ROOT}/scripts/packages.el" \ + --load="${ROOT}/scripts/export-org.el" \ + 2>> build.log + +INIT := --batch --load="${ROOT}/scripts/packages.el" \ + 2>> build.log + +.emacs : scripts/packages.el + @cleopatra echo Initiating "Emacs configuration" + @${EMACS} ${INIT} + @touch .emacs + +%.html : %.org scripts/packages.el scripts/export-org.el \ + .emacs org.mk + @cleopatra echo Exporting "$*.org" + @${EMACS} $< ${EXPORT} +#+end_src + +#+begin_src emacs-lisp :tangle scripts/packages.el +(use-package ox-tufte :ensure t) +#+end_src + +We also use the OCaml backend for ~org-babel~ to ensure our OCaml +snippets are well-typed, among other things. + +#+begin_src emacs-lisp :tangle scripts/packages.el +(use-package tuareg :ensure t + :config + (require 'ob-ocaml)) +#+end_src + +#+begin_src emacs-lisp :tangle scripts/export-org.el +(cleopatra:configure) + +(org-babel-do-load-languages + 'org-babel-load-languages + '((dot . t) + (shell . t) + (ocaml . t))) + +(setq org-export-with-toc nil + org-html-htmlize-output-type nil + org-export-with-section-numbers nil) + +(add-to-list 'org-entities-user + '("im" "\\(" nil "<span class=\"imath\">" "" "" "")) +(add-to-list 'org-entities-user + '("mi" "\\)" nil "</span>" "" "" "")) + +(defun with-keyword (keyword k) + "Look-up for keyword KEYWORD, and call continuation K with its value." + (pcase (org-collect-keywords `(,keyword)) + (`((,keyword . ,kw)) + (when kw (funcall k (string-join kw " ")))))) + +(defun get-keyword (keyword) + "Look-up for keyword KEYWORD, and returns its value" + (with-keyword keyword (lambda (x) x))) + +(defun get-org-title (path) + "Fetch the title of an Org file whose path is PATH." + (with-temp-buffer + (find-file-read-only path) + (get-keyword "TITLE"))) + +(defun insert-title () + "Insert the title of the article." + (with-keyword + "TITLE" + (lambda (title) + (insert + (format "\n\n@@html:<h1>@@ %s @@html:</h1>@@\n\n" title))))) + +(defun insert-series () + "Insert the series root link." + (with-keyword + "SERIES" + (lambda (series) + (insert "\n\n#+attr_html: :class series\n") + (insert series)))) + +(defun insert-series-prev () + "Insert the series previous article link." + (with-keyword + "SERIES_PREV" + (lambda (series-prev) + (insert "\n\n#+attr_html: :class series-prev\n") + (insert series-prev)))) + +(defun insert-series-next () + "Insert the series next article link." + (with-keyword + "SERIES_NEXT" + (lambda (series-next) + (insert "\n\n#+attr_html: :class series-next\n") + (insert series-next)))) + +(defun insert-nav () + "Insert the navigation links." + (when (get-keyword "SERIES") + (insert "\n\n#+begin_nav\n") + (insert-series) + (insert-series-prev) + (insert-series-next) + (insert "\n\n#+end_nav\n"))) + +(beginning-of-buffer) +(insert-nav) +(insert-title) + +(let ((outfile (org-export-output-file-name ".html")) + (org-html-footnotes-section "<!-- %s --><!-- %s -->")) + (org-export-to-file 'tufte-html outfile nil nil nil t)) +#+end_src |