Export gemini links from orgmode to markdown
Today, finally a short post (for real) as oppose to my usual lengthy posts!
I’m currently working on deploying again my blog as a gemini capsule (if you don’t know what the gemini protocol is, read about it here) as I haven’t deployed any update to my gemini capsules for more than a year. While doing so, I had an issue when exporting my posts writen in org mode to markdown: each gemini:// link where ignore and removed in the exported file.
For example, a link in org mode like [[gemini://gmi.bacardi55.io][My capsule]] was exported as [My capsule]() in markdown. Which of course was an issue as I didn’t want to fix the generated markdown manually…
The solution, as usual, was clearly explained in the orgmode manual: I needed to add an hyperlink type and tell emacs how to export it. When you add a new hyperlink type, you can tell emacs how to store, open and/or export those links. As I was lazy, I just configure how to export those links in different format.
To do so, I added the following elisp code, 100% inspired from the above documentation page:
(defun org-geminilinks-export (link description format _)
"Export a gemini link from Org files."
(let ((path (format "gemini:%s" link)) ;; %s contains the 2 starting slash
(desc (or description link)))
(pcase format
(`html (format "<a target=\"_blank\" href=\"%s\">%s</a>" path desc))
(`latex (format "\\href{%s}{%s}" path desc))
(`texinfo (format "@uref{%s,%s}" path desc))
(`ascii (format "%s (%s)" desc path))
(`md (format "[%s](%s)" desc path))
(t path))))
(org-link-set-parameters "gemini"
:export #'org-geminilinks-export)
If, like me, you are using doom emacs, add the above quote within an after! ox command:
(after! ox
[code from above]
)
Next step is to define how to store and open those links, but for now it will do as I want to focus on the new pipeline to build and deploy my capsule that has been in a staled phase for far too long.