Post

jekyll - a static site generator

Some tips and trick for using jekyll static site generator.

jekyll - a static site generator

jekyll https://jekyllrb.com/ is a static site generator and it uses liquid template language. It is build on top of ruby programming.

How to create a new jekyll project?

  • jekyll new - this creates a new jekyll
  • maxima is the default theme which is used

Table of contents in jekyll (github pages)

  • If you are using jekyll with github pages, as it does not support custom plugins so you have to use some java script.
  • But you can use this instead - https://github.com/allejo/jekyll-toc, which uses liquid language to parse a create a simple table of contents.

Some tips and tricks

Create a tags page

  • if your posts have metadata tags, then you can create a page for tags which will give a page of posts by tags
{%- assign sortedTags = site.tags | sort -%} <div class="tag-list"> {% for tag in sortedTags %} <a href="#{{tag[0]}}">{{ tag[0] }}&nbsp;({{ tag[1] | size }})</a> {% endfor %} </div> {% for tag in sortedTags %} <section class="posts-by-tag"> <h2 id="{{ tag[0] }}">{{ tag[0] }}</h2> {% for post in tag[1] %} {% include blog-listing.html %} {% endfor %} <p><a href="#" class="internal-link">All Tags &#8593;</a></p> {% endfor %}

List of all posts

{%- assign dateOfPost = {{post.date | date: "%d"}} -%} {%- if dateOfPost == "01" or dateOfPost == "21" or dateOfPost == "31" -%} {%- assign ordinalEnding = "st" -%} {%- elsif dateOfPost == "02" or dateOfPost == "22" -%} {%- assign ordinalEnding = "nd" -%} {%- elsif dateOfPost == "03" or dateOfPost == "23" -%} {%- assign ordinalEnding = "rd" -%} {%- else %} {%- assign ordinalEnding = "th" -%} {%- endif %} {%- assign firstDigitDofP = dateOfPost | slice: 0 -%} {%- if firstDigitDofP == "0" -%} {%- assign prettyDateOfPost = dateOfPost | slice: 1 -%} {%- else -%} {%- assign prettyDateOfPost = dateOfPost -%} {%- endif -%} <p> <a href="{{ post.url | relative_url }}" title="{{ post.title }}" class="blog-listing-link">{{ post.title }}</a><br> <time datetime="{{ post.date | date: '%Y-%m-%d' }}">{{ post.date | date: "%B" }} {{prettyDateOfPost}}{{ordinalEnding }}, {{ post.date | date: "%Y" }}</time> </p>

Write jekyll tags in the post without getting parsed

  • Enclose that text with {% raw %}{ % endraw %} tag. I have also done same in this post.
This post is licensed under CC BY 4.0 by the author.