Skip to content

Instantly share code, notes, and snippets.

@alexispurslane
Created February 6, 2025 20:51
Show Gist options
  • Save alexispurslane/858bbc95ed721c8c0d2592336bbc277f to your computer and use it in GitHub Desktop.
Save alexispurslane/858bbc95ed721c8c0d2592336bbc277f to your computer and use it in GitHub Desktop.
Advanced org-mode sitemap
(defun user/home-page-sitemap (title list)
"Create a sitemap that allows the user to add a custom preamble, and has not just the top level file structure of your org mode project, but also the top level headings of the top level files, in case you use top level files as categories in a note ontology as I do."
(concat
"
#+begin_export html
<div>
<style scoped>li { padding-top: 0px; }</style>
#+end_export
"
(org-with-file-buffer (concat quake-org-home-directory "blog/sitemap-preamble.org")
(buffer-string))
(org-publish-sitemap-default
title
(cl-loop for li in list
when (and (listp li)
(length= li 1))
collect (when-let ((link (with-temp-buffer
(insert (car li))
(goto-char 2)
(mark-sexp)
(cadr (string-split (buffer-substring-no-properties
(+ (region-beginning) 1)
(- (region-end) 1))
":")))))
(let ((result (list (car li)
`(unordered
,@(org-with-file-buffer (concat quake-org-home-directory "blog/" link)
(cl-remove '(nil)
(org-map-entries
(lambda ()
(let ((hcs (org-heading-components)))
(list (when (< (nth 1 hcs) 2)
(format "[[id:%s][%s]]"
(org-entry-get nil "ID")
(nth 4 hcs)))))))
:test #'equal))))))
(message "%S" result)
result))
else
collect li))
"
#+begin_export html
</div>
#+end_export"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment