Nikita Shmakov bio photo

Nikita Shmakov

Software Engineer

Twitter Facebook Google+ LinkedIn Github Last.fm Coursera

How I filter posts in my Jekyll blog

Some time ago I decided to write a part of my blog in english. There already were a few articles written in russian, thus I needed to apply some filtering mechanism to separate they into different pages.

At first, I moved my old posts index page template into _includes directory and created two different layouts for both languages with simple content:

{% include posts-index.html lang="eng" %}

and

{% include posts-index.html lang="rus" %}

Next, I added lang variable with corresponding value to the front matter of every post and used it in my partial template. Since my Jekyll theme uses non-trivial grouping of posts, it’s impossible to use if statement, but Jekyll supports filtering and assigning to a new variable:

{% assign filtered = (site.posts | where: "lang", include.lang) %}

Now, filtered contains only required posts.


comments powered by Disqus