Marking blog posts as drafts in 11ty
Post #14 published on by Tobias Fedder
One of the things I like about software is that sometimes all I need to do is apply an update, then something that didn’t work before starts working, or something that had been hard to achieve previously becomes a lot easier.
That is also the case for having drafts of blog posts excluded when Eleventy (11ty) builds this site for production. Even better, I don’t have to update anything, because I already did. Last time I tried to accomplish that I was still on 11ty version 2.0.1 and I was using eleventy-navigation
in version 0.3.5.
Back then there was a Quick Tip about excluding sources marked as drafts from builds, by setting their permalink
to false and excluding them from all collections. But unfortunately, I couldn’t get it working. Maybe I am doing something weird with collections that tripped up the navigation plugin? Maybe I was too stupid to copy and paste the code from the documentation? Either way, I gave up and used branches in my git repository instead, to deal with the occasional blog post draft.
However, there is a draft markdown file in my repo — has been there for a couple of months by now, because I just can’t get the text right — and the branch switching and rebasing started to annoy me. Remembering that there was quite a version bump for the navigation plugin, I’ve decided to give it another go. Currently I have 11ty at 3.1.2 and the eleventy-navigation
’s version is 1.0.4.
I jumped over to the 11ty docs and found out that in the meantime 11ty introduced the Preprocessor Configuration API, which reduces the amount of code needed to exclude drafts to 5 lines of code — 3, if you don’t count lines consisting of whitespace and closing parentheses. Due to the removal at the stage of preprocessing all the issues with pages in collections that were kinda, but not really, there, are gone.
So, if you gave up on excluding drafts from your 11ty site a while ago — or trying similar stuff around excluding pages from collections — maybe check your current version and try again.