Mateusz Loskot :: hacking on, working out, living up

Hakyll posts in folders

15 Dec 2012 | mloskot

I applied another quick improvement to my Hakyll configuration inspired by Ian Ross’ blog (what a great resource for Hakyll ideas).

I switched all my posts from flat file-based structure to layout with each post sitting in its own dedicated folder. For example, this old post:


now lives in its own folder:


This is mostly a cosmetic change, but I can see it has advantages if used with static site generators: * allows bundle all files related to posts in separate post-specific folder * helps to keep the whole site a self-contained package * a self-contained website is easy to move around, export, backup * makes it possible to use URLs without .html extension

The switch was quick and easy using the following script:

# - switches blog to folder-based posts
[[ -d ${POSTSDIR} ]] || ( echo "Directory '${POSTSDIR}' does not exist"; exit 1; )
POSTS=$(find ${POSTSDIR} -name '*.markdown')
for post in ${POSTS};
    [[ -d ${postdir} ]] && 
        ( echo "Deleting existing '${postdir}' folder"; rm -r ${postdir}; )
    mkdir ${postdir}
    echo "Created '${postdir}'"
    git mv ${post} ${newpost}
    echo "Moved '${post}' to '${newpost}'"

and the whole procedure involved these few steps:

cd /path/to/
./ ./posts
git commit -m "Switched to posts in folders" .
git push origin master

Now, I only need to implement rules for copying post resources like images, source code files, and others.

Fork me on GitHub