====== Blogging with Jekyll ======

----

===== Contents =====

  * [[#introduction|Introduction]]
    * [[#advantages|Advantages to using Jekyll]]
  * [[#gettingstarted|Getting started]]
  * [[#liquid|Using the Liquid templating language]]
    * [[#output|Output markup]]
    * [[#tag|Tag markup]]
  * [[#templates|Creating templates]]
    * [[#defaulttemplate|Default template]]
    * [[#posttemplate|Post template]]
    * [[#othertemplates|Other templates]]
  * [[#index|Creating the index page]]
  * [[#post|Writing a post]]
  * [[#build|Building the site]]

===== [[|Introduction]] =====

From the [[http://wiki.github.com/mojombo/jekyll|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]] ====

  * **No databases required.** Jekyll converts marked up text files to HTML files.
  * **No dynamic pages.** With Jekyll your site will be composed solely of static HTML files. No CGI is necessary, reducing the load on SDF servers.
  * **Ease and simplicity of use.** Using Jekyll does not require any programming knowledge, and the learning curve is very shallow. At the same time, the user does not sacrifice any control to wizards and GUIs.

===== [[|Getting started]] =====

Create a source directory with the following structure:

  * **"_config.yml"** This is the configuration file. Any settings put in here could also be declared as arguments after the "jekyll" command, but that would be a little messy. A complete explanation of options can be found [[http://wiki.github.com/mojombo/jekyll/configuration|here]].
  * **"_layouts/"** This directory contains the layouts to be used throughout the site. The following files should be placed in this directory, and more layouts can be added later. They are not actual HTML files.
    * **"default.html"** This is the layout that will be used by every page on the site. It will determine the overall look and layout.
    * **"post.html"** This layout will be applied to the posts on the blog.
  * **"_posts/"** This directory is home to all posts. Posts are named "YYYY-MM-DD-title-of-post.textile", assuming Textile formatting is used.
  * **"index.html"** This is obviously the index file. Despite the file name extension, it requires a special layout so that it can be interpreted by the Liquid engine.

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 "{{ variable | 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 [[http://wiki.github.com/mojombo/jekyll/template-data|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, [[http://wiki.github.com/tobi/liquid/liquid-for-designers|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 [[http://wiki.github.com/mojombo/jekyll/liquid-extensions| 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 "&lt;title&gt;{{ page.title }}&lt;/title&gt;". 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 "{{ page.date | 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 [[http://redcloth.org/hobix.com/textile/|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!

----

  $Id: jekyll.html,v 1.5 2010/07/24 14:30:14 nerfling Exp $