-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.el
78 lines (67 loc) · 2.52 KB
/
build.el
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
(require 'ox-tufte)
(require 'f)
(require 'ht)
(require 'mustache)
(require 'ts)
(defcustom input-file "./index.org"
"Input org file to transform")
(defcustom output-file "./docs/index.html"
"Output html")
(defcustom output-atom-file "./docs/atom.xml"
"Atom feed file")
(defcustom root-title "paper-reading | vernacular.ai"
"Page title")
(defcustom root-url "https://vernacular-ai.github.io/paper-reading"
"Main url for page")
(defvar atom-template "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<feed xmlns=\"http://www.w3.org/2005/Atom\">
<title>{{ root-title }}</title>
<link href=\"{{ root-url }}\"/>
<link href=\"{{ root-url }}/atom.xml\" rel=\"self\"/>
<updated>{{ root-date }}</updated>
<author><name>{{ root-author }}</name></author>
{{#entry}}
<entry>
<title>{{ title }}</title>
<updated>{{ date }}</updated>
<content type=\"xhtml\">
<div xmlns=\"http://www.w3.org/1999/xhtml\">
{{{ content }}}
</div>
</content>
</entry>
{{/entry}}
</feed>"
"Template for atom.xml file")
(defun parse-hl-content (hl)
(let* ((section (car (org-element-contents hl)))
(org-text (buffer-substring-no-properties (org-element-property :contents-begin section)
(org-element-property :contents-end section))))
(with-temp-buffer
(org-mode)
(insert org-text)
(let ((org-export-show-temporary-export-buffer t))
(org-html-export-as-html nil nil nil t)
(buffer-string)))))
(defun parse-entries ()
"Parser entries to make feeds of from the current buffer."
(mapcar #'ht<-alist
(org-element-map (org-element-parse-buffer) 'headline
(lambda (hl)
(let ((title (org-element-property :raw-value hl)))
`(("title" . ,title)
("content" . ,(parse-hl-content hl))
("date" . ,(ts-format "%FT%T%z" (ts-parse title)))))))))
(defun format-atom ()
(mustache-render atom-template
(ht ("root-title" root-title)
("root-author" "Vernacular.ai")
("root-url" root-url)
("root-date" (ts-format "%FT%T%z" (ts-now)))
("entry" (parse-entries)))))
(with-current-buffer (find-file-noselect input-file)
(let ((org-export-show-temporary-export-buffer t))
(org-tufte-export-to-buffer)
(f-write-text (buffer-string) 'utf-8 output-file)))
(with-current-buffer (find-file-noselect input-file)
(f-write-text (format-atom) 'utf-8 output-atom-file))