summaryrefslogtreecommitdiffstats
path: root/site/cleopatra/org.org
blob: 829272b720ca5cbed19d197935a6c590ef3d5bc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#+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

#+begin_src emacs-lisp :tangle scripts/export-org.el
(cleopatra:configure)

(org-babel-do-load-languages
 'org-babel-load-languages
 '((dot . t)
   (shell . 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