I'm trying to inject backlinks (org-roam user) into
<nav> ... </nav> html5 section at the end of my
<article> section during ox-export. Idea was to obtain something like that :
<nav> <ul> <li> <a href = "" > backlink 1 </li> <li> <a href = "" > backlink 2 </li> </ul> <nav>
Links need to be transformed from org to html, so i use a hook 'org-export-before-processing-hook' to inject org before processing.
ox-slimhtml derived backend because html5 output is simple and more semantic.
My first attempt was using s-wrap with
#+HTML: but i also try the
#+HTML_POSTAMBLE from ox-slimhtml without success.
(defun convert (l) (-mapcat (lambda (x) (list (car x) ( cdr x))) l)) (defun gx/get-backlinks (buf) (-flatten (convert (-take 1 (-unzip (org-roam--get-backlinks buf)))))) (defun gx/org-export-preprocessor (backend) (let ((backlinks (gx/get-backlinks (expand-file-name buffer-file-name)))) (when (and (not (null backlinks)) (consp backlinks)) (save-excursion (goto-char (point-max)) (insert (s-wrap (gx/format-links backlinks) "#+HTML:<nav>" "</nav> ")))))) (defun gx/format-links (links) (s-join "\n" (--map (org-roam--format-link it (org-roam--get-title-or-slug it)) links))) (add-hook 'org-export-before-processing-hook 'gx/org-export-preprocessor) (org-publish-all)
I take some time to make a MWE (publish.el + org files + html generated) with already published HTML to see the problem : https://filesender.renater.fr/?s=download&token=ba0cac2e-0ca2-47f0-97eb-425b42afe2a5
But i miss something and the outputted html is broken ...
I don't want to use
:html_postamble org-publish option because i suppose that operate after org processing. But, i'm beginning into elisp (two day to write ten working lines ...) so there are probably other solutions to do that than hacking this hook to inject HTML block.