Getting Started with Jekyll

This is a short tutorial that was presented at HICapacity on February 9, 2012.

The original slide deck can be found at:

Full source code for example can be found at:


  • Ruby (got RVM?)
  • RubyGems

Check out RVM when installing Ruby. RVM manages Ruby version allowing more than one version of Ruby to be installed. It is easy to switch between versions and maintain different sets of gems.


Once Ruby and RubyGems are installed install the gems for rdiscount and Jekyll:

    gem install rdiscount
    gem install jekyll

Rdiscount is used here but Maruku can used instead for interpreting markdown.

Basic Directory Structure

Jekyll sites will have a directory structure that looks like the following:

  • _config.yml - configuration file. Discussed more on the next slide.
  • _includes/ - folder with snippets of HTML that can be inserted into pages
  • _layouts/ - layouts for different pages of the site
  • _posts/ - folder of posts in markdown
  • _site/ - generated by Jekyll. The rest of the folders and config file should be created by the user.

Basic Configuration for _config.yml

    auto: false
    pygments: true
    markdown: rdiscount
    permalink: pretty
      extensions: [smart]
  • auto - tells Jekyll if it should monitor changes to files and regenerate the site automatically. Only applicable if running Jekyll as a server.
  • pygments - tells Jekyll that it should colorize code blocks using Pygments
  • markdown - markdown of choice
  • permalink - style of link to use for the site. "pretty" is a built in link style. For we use a custom one: /:year/:month/:day/:title/

Writing an includes


    <div style="border: 1px solid black">

An include is just a snippet of HTML. All snippets must be .html files. A perfect example of when to use an include is when writing a widget! Then they can be easily integrated into a site's sidebar and easily rearranged in any order. The snippet above is just a mock "widget" that lists some colors.

Writing a layout


    <!DOCTYPE html>
      <title>{{ page.title }}</title>
      <div id="sidebar" style="float: left; padding-right: 10px;">
        {% include widget1.html %}
        {% include widget2.html %}
      <div id="contents" style="float: left;">
        {{ content }}
      <div style="clear: both;"></div>

See the double curly braces? That is Liquid. Liquid is a templating language for Ruby.

Writing a post


    layout: post
    title: Post 1
    author: Test Author 1
    categories: ['Test', 'Jekyll']
    Hello World! This is test post 1.

    Nam auctor laoreet scelerisque. In porttitor varius interdum. Phasellus tempor vehicula sagittis...

See that at the top? That is YAML Front Matter. YAML front matter is a block of YAML that appears first in the file. This tells Jekyll that these files need special processing.

Displaying posts


    layout: default
    title: Posts
      {% for post in site.posts %}
        <h2><a href="">{{ post.title }}</a></h2>
        {{ post.content }}
      {% endfor %}

The code is iterating through all the posts for the site. It is showing them all on one page. The title of the post is link to the individual post. Note that it is possible to add pagination to a site so that not all posts end up on one page. The code is similar to that above but uses the paginator instead. Refer to the Jekyll wiki for more information.

Generating the site


NOTE: I mentioned earlier that Jekyll can be run as a server. While in this mode it can monitor the directory for changes and automatically regenerate the site as changes happen.

    jekyll --server --auto

Either option will generate the site in the _site folder. If the server option was used the site can be visited in a browser. The default port is 4000.