Export org-roam backlinks while publishing
Created on 2020-09-05T01:24:43+00:00
(defun benmezger/org-roam-export-all () "Re-exports all Org-roam files to Hugo markdown." (interactive) (dolist (f (org-roam--list-all-files)) (with-current-buffer (find-file f) (when (s-contains? "SETUPFILE" (buffer-string)) (org-hugo-export-wim-to-md))))) (defun benmezger/org-roam--backlinks-list (file) (when (org-roam--org-roam-file-p file) (mapcar #'car (org-roam-db-query [:select :distinct [from] :from links :where (= to $s1) :and from :not :like $s2] file "%private%")))) (defun benmezger/org-export-preprocessor (_backend) (when-let ((links (benmezger/org-roam--backlinks-list (buffer-file-name)))) (insert "\n** Backlinks\n") (dolist (link links) (insert (format "- [[file:%s][%s]]\n" (file-relative-name link org-roam-directory) (org-roam--get-title-or-slug link)))))) (add-hook 'org-export-before-processing-hook #benmezger/org-export-preprocessor))