Directory structure
The directory structure of this website is as follows (produced with M-x speedbar which does not show hidden files like .htaccess, etc.):
0:<+> css 0:<+> images 0:<+> posts 0:<+> tags 0:[+] 404.html * 0:[+] 404.org * 0:[+] Makefile * 0:[+] index.html * 0:[+] index.org * 0:[+] publish.el *
Additional CSS files live in the css directory:
extra.cssadds some styling not handled bysimplecss.syntax.cssproduced withhtmlize-bufferfromhtmlize.elhandles code highlighting.
Images used outside of posts, such as my profile picture, live in the images directory.
Posts
All posts and any associated files, such as images, live in their own directories under the posts directory. This setup of the posts makes it very easy to remove any post, and I do not need to worry about links to images and such. At the time of updating this post, the posts directory looks like as follows:
0:<-> posts 1: <+> braketx 1: <-> how-this-website-is-created 2: [+] index.html * 2: [+] index.org * 1: [+] index.html * 1: [+] index.org *
Tags
The tags directory is similarly arranged as the posts directory, one sub-directory for each tag. Each sub-directory contains an index.org file which lists all the posts corresponding to that tag. Originally I was using Python to create this, but now I have figured out an Emacs Lisp solution. To be honest I feel that the Emacs Lisp solution is simpler.
My original idea was:
- Build a hash table with tags as keys and list of corresponding posts as values.
- Create sub-directories for each tag under
tags. - Write the contents of the hash table to the
index.orgfiles in the sub-directories undertags. - Generate HTML files for the tags with Org publishing.
- Link each tag HTML file from its corresponding post HTML files.
The last bit required post-processing the generated HTML files. I failed to implement this with Emacs’s hash table. Implementing this with Python’s dict and regex searches was simple. But it was a fragile system. Changes, whether unintentional or due to carelessness, in the generated HTML can lead to spurious regex matches. My current Emacs Lisp solution is:
- Collect the tags for a post.
- For each tag, if
tags/<tag>/index.orgexists, then append relative link to the post to it, else create that file and add relative link to the post to it. - Repeat this for all posts.
Linking tags from posts is handled by my header function which uses built-in Org variables. This bypasses both post-processing the generated HTML, and regex matches. When publishing, I just recursively delete the tags directory and recreate it. This gets around the issue of checking existing links to posts for duplicates.