Getting started with Jekyll

Posted: March 25th, 2009 | Author: FreedomCoder | Filed under: Open Source, Programming, Rails, github | Tags: , , , | Comments Off

Jekyll is a simple static site generator created by Tom Preston-Werner that is used as the engine behind the well-known GitHub Pages.

I must admit that the first time I heard about this, the idea did not grab my attention at all. But after reading some inspiring blog posts about it, everything started to make sense and I decided to give it a try on my new blog, and so far, I like it.

Installing Jekyll

The easiest way to install Jekyll is via RubyGems:

  
    $ sudo gem install mojombo-jekyll -s http://gems.github.com
  

Notice that Jekyll requires directory_watcher, liquid, open4 and maruku. They will be automatically installed by the gem install command.

Creating content

Basically, what Jekyll does is to take several .textile or .markdown files and translates them into html, optionally using layout templates to avoid duplicating the common areas of our blog on each post. So, all we need to do is place our own content files in the correct locations.

A typical Jekyll blog setup would be as follows:

  • An index.html file on the root directory that will serve as the home page of our blog.
  • One or more template layouts in the _layouts directory. These layouts can then be referenced from any other file by using the layout attribute in the YAML header. Also notice that layouts can be nested.
  • One .textile or .markdown file for each post in the _posts directory.
  • One .textile or .markdown file for each draft in the _drafts directory. Any posts in this directory will be ignored by Jekyll at generation time.
  • One or more .textile or .markdown files in the _includes directory. Any files located in this directory can be included into another file with the include tag.

For a starting point, you might want to take a look at Tom Preston-Werner’s TPW repository.

Generating the blog

Once that the basic layout and content of our blog was set up, we are ready for telling Jekyll to generate our site:

  
    $ jekyll
  

If everything goes well, by now we should have our brand new Jekyll-powered blog generated on the _site directory.

We can also run Jekyll with the --server flag in order to test the generated site:

  
    $ jekyll --server
  

This flag tells Jekyll to launch a WEBrick server instance. Now we can point our web browser to http://localhost:4000 and test the generated site locally.

Publishing everything

At this point, we can just ftp the contents of the _site directory to our web site and we’re done.

However, a much better solution would be to create a remote git repository and add some git hooks there that take care of generating the site for us each time we do a simple git push. That is exactly the setup I am using to maintain this blog, and I will be writing about it in a future post.

Conclusion

This solution is definitely not for everyone. But if you are a programmer, and especially if you spend most of your day working with a text editor and a terminal window opened, then you may find the combination of Jekyll, Git, and your editor of choice (vim, in my case, but Emacs, TextMate or any other would work just fine, of course) more appealing than any traditional blog software.

(Via matflores.com.) Original Link: Getting started with Jekyll


Comments are closed.