blob: 31d2c6fbf5301414c46f2fe3822c406e31b98fc2 (
about) (
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
|
(unless (= 2 (length argv))
(error "Usage: emacs --script scripts/export-to-html <source-file> <output-file>"))
(let* ((source-filename (file-truename (elt argv 0)))
(output-filename (file-truename (elt argv 1)))
(source-buffer (find-file source-filename))
(output-buffer (find-file output-filename))
(html-buffer (get-buffer-create "*Org HTML Export*"))
(pt nil)
(file-buffer (current-buffer))
(org-html-toplevel-hlevel 1)
(org-html-head "")
(org-html-head-extra "")
(org-html-head-include-default-style nil)
(org-html-head-include-scripts nil)
(org-html-preamble nil)
(org-html-postamble nil)
(org-html-use-infojs nil)
(org-export-with-toc nil))
(with-current-buffer output-buffer
(erase-buffer))
(set-buffer source-buffer)
(org-next-visible-heading 1)
(while (not (equal pt (point)))
(setq pt (point))
(let ((title (org-get-heading t))
(id (org-element-property :CUSTOM_ID (org-element-at-point)))
(timestamp (org-read-date nil
t
(org-element-property :TIMESTAMP (org-element-at-point))
nil))
(tags (org-get-tags))
(subtree nil)
(html nil)
(hash nil))
(org-copy-subtree)
(setq subtree (with-temp-buffer (yank) (buffer-string)))
(org-html-export-as-html nil t t t)
(set-buffer html-buffer)
(setq html (buffer-string))
(set-buffer output-buffer)
(json-insert `((id . ,id)
(title . ,title)
(timestamp . ,(format-time-string "%FT%T%z" timestamp))
(tags . ,(vconcat tags))
(hash . ,(secure-hash 'sha256 subtree))
(source . ,subtree)
(html . ,html)))
(set-buffer source-buffer))
(org-forward-heading-same-level 1))
(set-buffer output-buffer)
(save-buffer))
|