Ognjen Regoje bio photo

Ognjen Regoje
But you can call me Oggy


I make things that run on the web (mostly).
More ABOUT me and my PROJECTS.

me@ognjen.io LinkedIn

Excluding content from a Jekyll post

#jekyll

Since I’ve restructured my blog to effectively publish the files that are my notes at the same time I’ve realized that sometimes I want to add notes to the blog files that might not be needed in the published post.

To do that I extended the original filter and creates the posts in Jekyll with this line:

new_doc.content = new_doc.content.split("< !-- exclude -->").reject{|x| x.include? "< !-- include -->"}.join("")

This lets me have content like this:

This is included
< !-- exclude -->
This is excluded
< !-- include -->
This is also included

It does have a limitation in that it cannot start with a section that’s excluded and it must be followed by the included delimiter.

Note the space in <!-- exclude-->. This is due to because the syntaxt highlighter plugin renders each term within a span which the interprets the rest of <!-- exclude--> as a comment.