Luke Campbell« luke.s.campbell@gmail.com » |
So, I've been debating for a while now how to get this blog out there. My first blog system (which no one ever visited) was a LAMP (Linux, Apache, MySQL and PHP), whereby the entire blog was created and dynamically generated with PHP. The dynamic blogging system was fun but it became really bogged down as more posts were added.
Enter static blogging. A number of people I know swear by static blogging and with powerful tools like Rails, Sinatra and Git, blogging in the 21st century can be magnificent!
First things first:
This article is a great place to start and a lot of what I'm saying here is re-iterated.
Get jekyll:
$ gem install jekyll
Get your own jekyll layout:
$ git clone https://github.com/mojombo/mojombo.github.com.git
You can rename your repository or do with it what you like, personally I renamed it. For the purpose of this article let's rename it to my_blog and change a few things:
Make changes to your index.html to fit your needs. Now comes the posts section! Erase all the files in _posts, then go ahead and populate them with your own .md files.
Typically your posts look like this:
--- layout: post title: Blogging for the Nerd --- {{ page.title }} ================ Your content goes here.
Now comes the rakefile, adopting from the above tutorial I have tweaked something into this:
# Rakefile require 'time' deploy_default = "heroku" deploy_branch = "master" deploy_dir = "_heroku" public_dir = '_site' github_dir = '_github' jekyll_path = '~/Workspace/jekyll/bin/jekyll' app_name = 'your_heroku_app_name' desc "deploy basic rack app to heroku" multitask :heroku do puts "## Deploying to Heroku " (Dir["#{deploy_dir}/public/*"]).each { |f| rm_rf(f) } system "cp -R #{public_dir}/* #{deploy_dir}/public" puts " ## copying #{public_dir} to #{deploy_dir}/public" cd "#{deploy_dir}" do system "git add ." system "git add -u" puts " ## Committing: Site updated at #{Time.now.utc}" message = "Site updated at #{Time.now.utc}" system "git commit -m '#{message}'" puts " ## Pushing generated #{deploy_dir} website" system "git push heroku #{deploy_branch}" puts " ## Heroku deploy complete" end end multitask :github do puts "## Deploying to Github " (Dir["#{github_dir}/public/*"]).each { |f| rm_rf(f) } system "cp -R #{public_dir}/* #{github_dir}/" puts " ## copying #{public_dir} to #{github_dir}/" cd "#{github_dir}" do system "git add ." system "git add -u" puts " ## Committing: Site updated at #{Time.now.utc}" message = "Site updated at #{Time.now.utc}" system "git commit -m '#{message}'" puts " ## Pushing generated #{github_dir} website" system "git push origin #{deploy_branch}" puts " ## Github deploy complete" end end desc 'Generate Layout' task :new_post do t = Time.now d = '_posts/' + t.strftime('%Y-%m-%d') + '.md' l = t.strftime('%d %B %Y') puts 'Generating new post' layout = <<DOC --- layout: post title: Title --- {{ page.title }} ================ DOC layout += "\n <p class='meta'>" + l + "</p>\n" File.open(d, 'w') do |f| f.puts layout end puts 'Created: ' + d end task :launch do system 'open http://' + app_name end task :jekyll do system jekyll_path + ' --auto --server' end
So ideally your directory structure should resemble this:
Blogroot |+_github/ |~_heroku/ | |+public/ | |-config.ru | |-Gemfile | `-README |~_layouts/ | |-default.html | `-post.html |~_posts/ | |-2012-01-01-Welcome.md | |-2012-01-16-Win.md | |-2012-01-20-Blog.md | `-2012-01-21-Applescript.md |+_site/ |~css/ | |-screen.css | `-syntax.css |~images/ | `-rss.png |+random/ |-_config.yml |-atom.xml |-CNAME |-index.html |-Rakefile `-README.textile
With all this you should be up and running and ready to go!