I previously implemented some lisp functions to allow me to generate list of
posts tagged with a certain topic. I later found a bug in that method (which
org-static-blog which I referenced in the last post). To specify
the tile of an org document you put
#+title: Document Title at the beginning.
However for long title, you can break this across multiple
Both techniques of using regexp and using
org-element-parse-buffer fail to
#+title: lines. However I’ve found
does, as it is how the org exporters get the title.
In the process of fixing this, I also came across another bug. Org specifies
that file-wide tags should be specified like so:
:Peter:Boss:Secret: however I was using white space to delimit tags (again
because this is how
org-static-blog does it).
Here’s the modified functions to show how I used
fix these bugs.
(defun my-org-get-env-key (post-filename key) "Extract the value of `#+title:`, `#+author:`, `#+date:`, or `#+filetags:` from post-filename." (with-temp-buffer (insert-file-contents post-filename) (plist-get (org-export-get-environment) key))) (defun my-blog-get-tag-tree () "Return an association list of tags to filenames. e.g. `(('foo' 'file1.org' 'file2.org') ('bar' 'file2.org'))`" (let ((tag-tree '())) (dolist (post-filename (my-blog-get-post-filenames)) (let ((tags (my-org-get-env-key post-filename :filetags))) (dolist (tag tags) (if (assoc-string tag tag-tree t) (push post-filename (cdr (assoc-string tag tag-tree t))) (push (cons tag (list post-filename)) tag-tree))))) tag-tree)) (defun my-blog-posts-to-list (post-filenames) (seq-reduce (lambda (acc el) (concat acc "\n- " el)) (seq-map (lambda (fname) (concat "/" (car (my-org-get-env-key fname :date)) "/ " (org-make-link-string (concat "file:" (file-relative-name fname)) (org-export-data-with-backend (my-org-get-env-key fname :title) 'org nil)))) post-filenames) ""))
The final bug (hopefully) is fixed by calling
the title string to convert the string-with-text-properties back into an
org-mode formatted string. Otherwise elements with org mode formatting such as
~code~ won’t appear in our listing of posts.
I can’t believe I went my entire undergrad at CMU without meeting Prof. Kitchin