how to org mode image absolute path of export html?
The way to do this is to register a new kind of link in org-mode, using org-add-link-type
. That lets you supply a custom export format.
org-add-link-type
requires a prefix, a "what happens when you click the link?" function, and an export function.
I use a prefix of img
, so my links look like [[img:logo.png][Logo]]
.
My image files are in ../images/
(relative to the .org files), and from the webserver they show up in /images/
. So for those settings, putting this in .emacs
provides the solution:
(defun org-custom-link-img-follow (path)
(org-open-file-with-emacs
(format "../images/%s" path)))
(defun org-custom-link-img-export (path desc format)
(cond
((eq format 'html)
(format "<img src=\"/images/%s\" alt=\"%s\"/>" path desc))))
(org-add-link-type "img" 'org-custom-link-img-follow 'org-custom-link-img-export)
You'll probably need to amend the paths for your setup, but that's the recipe. As you'd expect, C-hforg-add-link-type
will give you the full gory details.
Oh, and for what it's worth, here's the code I'm using for inter-post links (like [[post:otherfile.org][Other File]]
). There's a little Jekyll magic in the output format, so watch the double-%s.
(defun org-custom-link-post-follow (path)
(org-open-file-with-emacs path))
(defun org-custom-link-post-export (path desc format)
(cond
((eq format 'html)
(format "<a href=\"{%% post_url %s %%}\">%s</a>" path desc))))
(org-add-link-type "post" 'org-custom-link-post-follow 'org-custom-link-post-export)