Jekyll Blogging

A Jekyll blog might be more complicated than other approaches but it also offers high flexibility and many features.

You can install it yourself with:

gem install jekyll

Note

OSX users might need to update their RubyGems:

sudo gem update -system

Additionally there are many other options:

  • Using rdiscount or maruku
  • Using pygments for syntax highlighting
  • and this list could go on and on due to an amazing community support

For more information check the Jekyll Wiki

Posting

Posting with Jekyll doesn’t involve a nice interface but is still a lot more simple than other methods.

You can post with Markdown like me or use an alternative. Editing gets even better if you are on a Mac and you use a nice markdown editor like Mou.

This is how my Jekyll folder tree looks like:

root/
    _includes/
        disqus.html
        ...
    _layouts/
        default.html
        post.html
    _plugins/
        *.rb
    _posts/
        *.markdown
    _site/
        ...
    css/
        styles.css
        syntax.css
    images/
        twitter.png
        rss.png
        github.png
    javascript/
        ...

This might seem intimidating initially but after you’ve wrapped your head around it should be easy to understand.

_includes

You can place any .html files in here and then include them anywhere you want with the following tag:

{ % include FILE_NAME.html % }

This is especially helpful if you want to example use Disqus in your blog. I’ve included the javascript code in a disqus.html file and whenever I want to use it I can simply include it with the above tag.

_layouts

The files in here are going to be the basic building blocks of your site. At the top of this post:

layout: post

therefore i access the post.html file in _layouts. That post.html file is based of a default.html file. Therefore I don’t have to worry about any CSS or HTML after the site has been set up once.

_posts

All your posts go in here. Look at the end of this post to see how I have written this post.

Automatic Post Generation

thanks to Cody Krieger

Cody Krieger wrote a small little script:

 1 #!/usr/bin/env ruby
 2 
 3 # *********************************************
 4 # Jekyll Post Generator Awesomeness
 5 # by Cody Krieger (http://codykrieger.com)
 6 # *********************************************
 7 
 8 # Usage:
 9 # % ./newpost.rb POST NAME
10 
11 if ARGV.empty? or ARGV[0].downcase == "--help" or ARGV[0].downcase == "-h"
12   puts <<-USAGE
13 
14   Usage:
15   % ./newpost.rb POST NAME
16 
17   USAGE
18 
19   exit (ARGV.empty? ? 1 : 0)
20 end
21 
22 class String
23 
24   # from ruby on rails (https://github.com/rails/rails)
25   # activesupport/lib/active_support/inflector/transliterate.rb
26   def parameterize(sep = '-')
27     # replace accented chars with their ascii equivalents
28     parameterized_string = self.dup
29     # Turn unwanted chars into the separator
30     parameterized_string.gsub!(/[^a-z0-9\-_]+/i, sep)
31     unless sep.nil? || sep.empty?
32       re_sep = Regexp.escape(sep)
33       # No more than one of the separator in a row.
34       parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
35       # Remove leading/trailing separator.
36       parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
37     end
38     parameterized_string.downcase
39   end
40 
41 end
42 
43 TEMPLATE = "template.markdown"
44 POSTS_DIR = "_posts"
45 
46 # Get the title and use it to derive the new filename
47 title = ARGV.join(" ")
48 filename = "#{Time.now.strftime('%Y-%m-%d')}-#{title.parameterize}.markdown"
49 filepath = File.join(POSTS_DIR, filename)
50 
51 # Load in the template and set the title
52 post_text = File.read(TEMPLATE)
53 post_text.gsub!('%%TITLE%%', title)
54 
55 # Write out the post
56 post_file = File.open(filepath, 'w')
57 post_file.puts post_text
58 post_file.close
59 
60 puts "Successfully created file => #{filepath}"

Execution:

./newpost.rb Test Post

chmod u+x newpost.rb might be needed in order for the script to be executable.

The script is going to look for a file named template.markdown in you Jekyll root directory. This template is a basic Jekyll post that you have to fill in with your content.

---
layout: post
title: %%TITLE%%
published: true
---
Hello, Jekyll!

More on this can be found at Cody’s Blog

And if you are a Physics Lover like me you can easily embed Maxwell’s equations with LaTeX.

You can also do some in-line equations, for example: \( P(E) = {n \choose k} p^k (1-p)^{ n-k } \). That way you can make your posts - whatever they might be about - look quite pleasing.

Using Latex like this takes a little more than just writing down normal latex code but I am going to cover that in another post. But basically I am just using the awesome MathJax javascript library.

Check out my tutorial on how I did it!

Math Magic

Post Scriptum

The best thing is that you can just use Github Pages to deploy your blog:

git push origin master

It is as simple as that and you are all set!

Check out the original markdown of this post here.

By Cecil Wöbker


I do science during the day and develop or design at night. If you like my work, hire me.

Feel free to follow me on Twitter or email me with any questions.

Comments