Open Pelican relative path in emacs org
I'm using Pelican, a static site generator, to provide an html personal wiki or knowledge base using .org
files as its base. Links to internal content in Pelican use the syntax {filename}/path/to/file
. However, since I'm using emacs org-mode, I would also like to be able to follow such links to their relevant files in org-mode. I'm hoping that there is a simple function I could write which would allow org-mode to follow such a link and open the relevant file, without compromising Pelican's use of the internal link syntax. I suspect that this might be done by means of org-add-link-type
and a function which parses the proper absolute path to the file. But my elisp-fu is weak, and I'm unsure of how to proceed. Help appreciated!
Edit : just to give an example, I might have a link like [[file:{filename}/path/to/file.org]]
in an org file. Is there a way to get org to open the file by substituting (maybe via regexp?) an absolute file path for {filename}
, but also wouldn't alter the original link so that Pelican can still process it correctly?
I think you want something like:
#+BEGIN_SRC emacs-lisp
(org-add-link-type
"pelican"
(lambda (path) (org-open-file path))
;; ; export
(lambda (path desc backend)
(cond
((eq backend 'html)
(format "{filename}/%s" (file-relative-name path))))))
#+END_SRC
Link to internal content pelican:/Users/jkitchin/blogofile-jkitchin.github.com/_blog/blog.org
#+BEGIN_SRC sh
pwd
#+END_SRC
#+RESULTS:
: /Users/jkitchin/blogofile-jkitchin.github.com/_blog
exports to:
<p>
Link to internal content {filename}/blog.org
</p>
Using the original answer by John Kitchen as a basis to build upon (along with this answer), the best function I came up with is the following:
(org-add-link-type
"pelican"
(lambda (path) (org-open-file path))
;; ; export
(lambda (path desc backend)
(cond
((eq backend 'org)
(format "[[file:{filename}/%s][%s]]" path (or desc "")))
((eq backend 'html)
(format "<a href="%s">%s</a>" path (or desc "")))
((eq backend 'md)
(format "[{filename}/%s](%s)" path (or desc ""))))))
Depending on the backend used for org-publish
the function will provide relative links for org, html, or markdown.