Table of Contents

Blogging with Jekyll


Contents

[[|Introduction]]

From the Jekyll wiki:

Jekyll is a simple, blog aware, static site generator. It takes a template directory (representing the raw form of a website), runs it through Textile or Markdown and Liquid converters, and spits out a complete, static website suitable for serving with Apache or your favorite web server.

Jekyll is installed on SDF, making it a particularly useful tool for MOTD users but also for any user wishing to host a weblog on his SDF webspace.

[[|Advantages to using Jekyll]]

[[|Getting started]]

Create a source directory with the following structure:

Inside the “_config.yml” file, set the destination value to the directory that should contain the generated site:

” destination: /absolute/path/to/html ”

MOTD users may wish to put instead:

” destination: /absolute/path/to/html/motd ”

Replace “/absolute/path/to” with the path to your home directory. Type “echo $HOME” in the shell if you're unsure.

[[|Using the Liquid templating engine]]

Liquid is a templating engine with which all files ending in “.html” will be processed. These files can have normal HTML that will be interpreted literally. Liquid only cares about text in between “and” and in between “{%” and “%}”. The former denotes output markup, meaning that whatever is placed within the brackets can produce text. The latter denotes tag markup, which does not produce text but is used for comments, conditional statements, and loops.

[[|Output markup]]

Output markup is fairly simple. The basic format is “ filter ”. The variables are typically built into Jekyll, so one usually doesn't have to worry about declaring them. “site ” is a variable that stores site-wide information in sub-variables. For example, “site.posts” is a list of all the site's posts. Each post has its own “post” variable, which includes information such as “post.title”, “post.url”, and “post.date” Another important variable is “content”, which is used in templates to denote where the content will be inserted. A complete list of template data can be found here. Filters are used to manipulate theoutput of variables. When a filter is not specified (“variable”), the variable is simply printed. Liquid has a bunch of built-in filters that can be found, along with a whole summary of using Liquid, here. Jekyll also has some of its own filters, such as “number_of_words” and “array_to_sentence_string”, which turns an array variable into a list of words seperated by commas and an “and.” The complete list can be found here, along with Jekyll's extra tags.

[[|Tag markup]]

The most basic tag is “{% comment %}” / “{% endcomment %} ”. Anything in between those tags is ignored. Conditional statements are possible with “{% if condition %}” / “{% endif %}”. For loops are especially useful with Jekyll. Use them with “{% for item in array %}” / “{% endfor %}”.

[[|Creating templates]]

Let's actually get started with the blog. The first thing we need are the templates.

[[|Default template]]

Remember that the templates are stored in the “_layouts/” folder and that the default template is named “default.html”. Here we can put all of the HTML headers once and be done with them. This includes any meta information, a link to a stylesheet, a link to a feed, etc. For the title, we can use “<title>page.title</title>”. This way the title for every page will automatically get inserted. Once all of the headers are done, we can add some layout that will get used on every page. Finally, “content” must go where dynamic content of the site will be inserted.

[[|Post template]]

“post.html” determines the layout for post pages. Here we first encounter YAML front matter. YAML stands for “YAML Ain't a Markup Language,” Any YAML content is placed between “—” and “—” (each on their own line) at the beginning of a document. In this front matter we can set variables in the format, “variable: value”. The only variable we need to set for the post template is “layout: default”. This tells Jekyll to insert this template into “content” in the default layout. We'll also want to add a “content” to the post template. This is where the actual post will get inserted. We also might want to add somethings like “page.title” and “ date: "%A %d %B %Y" ”, which will format the post's date as “Weekday Day Month Year”.

[[|Other templates]]

Finally, once getting the hang of creating template, one can add new ones, such as “static.html” for static pages without a date.

[[|Creating the index page]]

The web site will of course need an index page, “index.html”. As usual, this will get interpreted by Liquid. But first we'll need to add the front matter. The layout should probably be default again. If any of the layouts use “page.title”, we can define the title of the home page now with “title: This Is My Title”. After the YAML front matter, we'll probably want a list of the posts. This can be done with a for loop: “{% for post in site.posts %}”. Format the HTML content inside the loop in any way, maybe using “post.date” and “post.title”.

[[|Writing a post]]

We have some different choices for the markup language for the posts, but we'll use Textile because it works just fine. Remember to name the file “YYYY-MM-DD-title-of-post.textile” and to put it in the “_posts/” directory. Again we'll start with the front matter. This time, we'll want “layout: post”, so that the output of the post will get inserted at “content” in the post template. If “page.title” was used anywhere else, the title must be declared now. Whatever comes after the YAML content must be in the Textile format, which is very easy to learn. A good reference can be found here.

One thing to watch out for is that any newline is interpreted as a new paragraph, so don't hit “return” unless you mean it.

[[|Building the site]]

Once we have our templates, index, and posts done, we can finally build the site. To do so, use the command “jekyll” in your source directory to generate the static HTML site, followed by “mkhomepg -p” to set the proper permissions on any newly-created files.

Congratulations, you now have a Jekyll-powered blog. All of this may have seemed complicated, but once you get the hang of it, maintaining your new site will be a breeze!