Filtering published documents by tag and/or category

I have a few hundred posts in a blog that have transferred to Jekyll. Some of these posts are tagged as private. I would like a way to filter these posts out when I build the site so they do not exist in the built site at all.

As far as I can see there is no option to do this. If I am wrong on this please let me know of course… meanwhile I have tried to implement a solution to the problem.


I have taken a quick look at the code and found it’s easily extended to support this with additional checks in lib/jekyll/publisher.rb fed from command-line options fed in by lib/jekyll/command.rb and lib/jekyll/site.rb.

I initially implemented a --private option and excluded posts having a private tag unless this option is given:

--private      Render posts that were marked as private

I’ve made a fork of the repo and have committed this change to a fetaure branch.

That solves my own immediate need but it is specific to a tag that I use. I thought I would make it generic and support inclusion and exclusion of tags and/or categories. I implemented four options:

--with-categories CAT[,CAT,...]  Render posts that have any of these categories
--without-categories CAT[,CAT,...]  Render posts that do not have any of these categories
--with-tags TAG[,TAG,...]  Render posts that have any of these tags
--without-tags TAG[,TAG,...]  Render posts that do not have any of these tags

I have committed this change to another feature branch.

I’m just looking for feedback on this right now but I am ready to submit either of these as a pull request if that would be useful.

1 Like