ZeroSharp

Robert Anderson's ones and zeros

Octopress on Windows and GitHub

| Comments

There is a more recent version of this post which covers ruby 1.9.3, python 2.7.3.




This is quick guide to setting up Octopress on a Windows 7 machine to publish to GitHub pages. It relies on ruby 1.9.2 and python 2.7.2.

Get with GitHub

First, get an account on GitHub and follow the excellent instructions for Windows here. here.

Once you are set up with GitHub, get yari by opening a command prompt:

Then create a directory for all your github projects. You could put this anywhere, e.g., %USERPROFILE%\github. I chose to create a directory C:\projects\github\.

Installing Octopress

Use yari instead of RVM/rbenv

Scott Muc has written yari which lets you switch between Windows Ruby versions. Get it with the following command.

cd C:\projects\github\
git clone git://github.com/scottmuc/yari.git yari

Once this has completed you can setup the required Ruby environment with the command:

yari 1.9.2

Then follow the rest of the instructions from the Octopress setup instructions.

git clone git://github.com/imathis/octopress.git octopress
cd octopress
ruby --version  # Should report Ruby 1.9.2 thanks to yari

Next install dependencies

gem install bundler
bundle install

Install the default Octopress theme.

rake install

Deploying to GitHub

The instructions are here. The only difficulty I had was working out which URL to use after:

rake setup_github_pages

This will ask you for your Github Pages repository url, but it is not clear that this is the SSH one, e.g., git@github.com:ZeroSharp/zerosharp.github.com.git. You can find it near the top of the repository page.

Configuring your blog

Follow the instructions here to configure your blog.

Markdown

It is quite difficult to find good help on the markdown syntax other than for the codeblocks section. For instance, it is not clear how to generate a codeblock with no line numbers, like this one:

How do I output a codeblock with no line numbers?

It turns out it either requires a <pre> tag instead of a { codeblock } tag, or alternatively, start the line with four spaces. The official syntax is here, but I also found this cheat sheet.

Fonts and Styles

See Lee’s Bigdinosaur blog.

Problem with CodeBlocks

I had a problem with codeblocks which seems to be specific to Windows. It seems that whenever you include a lang parameter in a codeblock, you get:

Liquid error: No such file or directory - python2.7 -c “import sys; print sys.executable”

There are two issues:

  • Syntax highlighting requires Python which is not automatically installed.
  • There is a problem with pythonexec.rb which does not seem to support Windows Python installations very well.

Luckily we can fix them both. Install Python 2.7.2. Actually I used ninite.com to install it.

Then modify the pythonrubyexec.rb which is in the depths of the yari subdirectory. Try here: .\yari\ruby-1.9.2-p290-i386-mingw32\lib\ruby\gems\1.9.1\gems\rubypython-0.5.1\lib\rubypython\pythonexec.rb

At the top of pythonexec.rb, modify the file as follows:

pythonexec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class RubyPython::PythonExec
  # Based on the name of or path to the \Python executable provided, will
  # determine:
  #
  # * The full path to the \Python executable.
  # * The version of \Python being run.
  # * The system prefix.
  # * The main loadable \Python library for this version.
  def initialize(python_executable)
    @python = python_executable || "python"

+    if (@python.include? 'python2.7')
+      @python = "python"
+    end

    @python = %x(#{@python} -c "import sys; print sys.executable").chomp

References

Comments