diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org> | 2019-04-22 15:59:59 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org> | 2019-04-22 15:59:59 -0400 |
| commit | efbfba0d9dbf14766b90dea5a78e6d7f97630f24 (patch) | |
| tree | 61249f646b8a0c2d5d99d87e98ef08f89aee0972 | |
| parent | ce954b504720daa71cd0b017986561c7411ccc7b (diff) | |
Intercept 'org-html-link to copy static images
| -rw-r--r-- | ox-haunt.el | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/ox-haunt.el b/ox-haunt.el index 1d00a99..3e2cca3 100644 --- a/ox-haunt.el +++ b/ox-haunt.el @@ -43,7 +43,10 @@ (if a (ox-haunt-export-to-html t s v b) (org-open-file (ox-haunt-export-to-html nil s v b))))))) :translate-alist - '((template . ox-haunt-template))) + '((link . ox-haunt-link) + (template . ox-haunt-template)) + :options-alist + '((:hugo-base-dir "HAUNT_BASE_DIR" nil nil))) (defgroup org-export-haunt nil "Options for exporting Org mode files to Haunt HTML." @@ -65,6 +68,23 @@ valid executable." "A list of keywords to include in the Haunt metadata section." :type '(list symbol)) +(defun ox-haunt--check-base-dir (dest-path) + (unless dest-path + (user-error "It is mandatory to set the HAUNT_BASE_DIR property")) + (unless (file-directory-p dest-path) + (user-error "The HAUNT_BASE_DIR property must name a directory"))) + +(defun ox-haunt-link (link desc info) + "Transcode a LINK object from Org to HTML." + (let* ((orig-path (org-element-property :path link)) + (filename (file-name-nondirectory orig-path)) + (dest-path (plist-get info :hugo-base-dir))) + (when (string= "file" (org-element-property :type link)) + (ox-haunt--check-base-dir dest-path) + (copy-file orig-path (concat dest-path "/images/" filename) t) + (org-element-put-property link :path (concat "./images/" filename))) + (org-html-link link desc info))) + (defun ox-haunt--keyword-as-string (info keyword) "Obtain the value of KEYWORD as a plaintext string." (org-export-data-with-backend (plist-get info keyword) 'ascii info)) |