diff options
author | Masaya Tojo <masaya@tojo.tokyo> | 2024-03-17 18:53:22 +0900 |
---|---|---|
committer | Masaya Tojo <masaya@tojo.tokyo> | 2024-03-17 18:53:22 +0900 |
commit | a99ad1e68c06c33e8ec87642b2b1a21ce61ebdd2 (patch) | |
tree | 7a953ce320c6e77f5dca58caf15c680aa57b108a /scripts/export-to-html.el | |
parent | 4b5b80ee829f58d67352aa88bd10fac15b242cc6 (diff) |
Add scripts for org file to json data.
Diffstat (limited to 'scripts/export-to-html.el')
-rw-r--r-- | scripts/export-to-html.el | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/export-to-html.el b/scripts/export-to-html.el new file mode 100644 index 0000000..5e66e9d --- /dev/null +++ b/scripts/export-to-html.el @@ -0,0 +1,56 @@ +(unless (= 2 (length argv)) + (error "Usage: emacs --script scripts/export-to-html <source-file> <output-file>")) + +(let* ((source-filename (elt argv 0)) + (output-filename (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)) + (with-current-buffer output-buffer + (erase-buffer)) + + (set-buffer source-buffer) + (org-next-visible-heading 1) + (while (not (equal pt (point))) + (setq pt (point)) + (terpri) + (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)) + (html . ,html))) + + (set-buffer source-buffer)) + (org-forward-heading-same-level 1)) + + (set-buffer output-buffer) + (save-buffer)) |