Mean in green
I'm Kevin. I live in Salem, Mass with my wife and little boy and I build software.

Jekyll Configuration

Wednesday Dec 19, 2012

I've been playing around with quite a bit of configuration since moving to Jekyll and thought I would take a few minutes to jot down some of the things I've done.

Syntax Highlighting

I'm using pygments to do content shading and a slightly modified version of the mojombo's syntax.css to work on a dark background. The result is pretty sweet:

<?php

// Random Variable.
$a = array("one", "two", "three");

foreach ($a as $i) {
  print $i;
}

Clean URLs

Moving from Drupal, I needed a way to maintain my clean URLs. Since Jekyll creates static files, you can't quite make a URL like "/content/my-page". Thankfully webservers are smart enough to use a directory index file, so if there is a directory "/content/my-page/" that will work just fine as a request URI. There are a few solutions out there, but this one worked out pretty well. The trailing slash isn't the nicest looking, but I can live with that... removing it is a pain.

You can automate this in your global config, then create the file _posts/2012-12-19-my-page.MARKUP

# _config.yml
permalink:   /content/:title
# generates URLs like /content/my-page/

Or if you need to get more specific, you can place the permalink in the post's front-matter.

---
# _posts/2012-12-19-random.MARKUP
permalink: /content/my-page/
# generates the URL /content/my-page/
---

Pagination and Liquid variables

I chose to use the recommended method to create a paginated list of posts. When you do this, you get a bunch of variables that are passed along from your posts, but you can also pass custom variables from your front matter yaml. For example, if you want to provide a custom teaser for your post, you can specify it in your post:

---
# _posts/2012-12-19-random.MARKUP
title: "My Post"
teaser: "Something about my post goes here."
---

Then you get access to that in your paginated list:

{% for post in paginator.posts %}
  <!-- here add you post markup -->
  <h3><a href="{{ post.url }}">{{ post.title }}</a></h3>
  <div class="date">{{post.date | date: "%A %b %d, %Y"}}</div>
  <div class="content">
    {% if post.teaser %}
      {{ post.teaser }}
    {% else %}
      {{ post.content | strip_html | truncatewords: 25 }}
    {% endif %}
  </div>
{% endfor %}

There are a ton of other things I've done, but those are just a few of the more interesting ones. I'm trying to keep up blogging and this seems to at least get some words on the page. More to come!