lekaha's blog Change the world     Wiki     Blog     Feed

How to build your blog with Jekyll and IPython

What is Jekyll

I used the introduction of Jekyll as the first post. If you’re interested you can talk look the post.

What is IPython

IPython provides a rich architecture for interactive computing with:

  • A powerful interactive shell.
  • A kernel for Jupyter.
  • Support for interactive data visualization and use of GUI toolkits.
  • Flexible, embeddable interpreters to load into your own projects.
  • Easy to use, high performance tools for parallel computing.

I usually use it as notebook to note something I learn or note something I experiment.

Why I put them together

Since I would like to start to write blogs as to note what I am learning and have used IPython notebook as my note while I pratice Machine learning with Python. So I think they can be put together.

Let’s start

I am not going to describe how to put blogs on Github.io but here I will use it as my blogs endpoint.

Repository

I put Jekyll project on Bitbucket rather than directly put the project on Github. Since Github limited packages in Jekyll I can not convert IPython notebook to blog with customized package. So I decided put the static web site only in Github and put Jekyll project to a private git repository, e.g. Bitbucket.

Here is my case: - Github: your_name.github.io - Bitbucket: your_name.site

Covert IPython notebooks to blog

IPython’s built-in Markdown conversion

ipython nbconvert --config jekyll-post notebook.ipynb

To use this conversion you have to put two files in the same path.

  • Script:

Note:

Image files will be put at the img folder. The part of code in the script to describe below where the images will be put.

def path2url(path):
    """Turn a file path into a URL"""
    parts = path.split(os.path.sep)
    print os.path.sep, parts
    return '/img/' + '/'.join(quote(part) for part in parts)

  • Template:

Build script

  • Install a make-like build utility for Ruby - Rake
  • Then, put your nodebooks (.ipynb) into notebooks folder.
  • The build script will covert all of notebooks to markdown file. (.md)
  • Since notebooks conversion would generate image files in the same path with notebooks we should move images to img folder after coverted.
  • Move all markdown files to _post folder for building by Jekyll.
  • Finally, copy all output that are the web site files to GH_PAGES_DIR in the upper folder.

Push to repositories

Remember to commit and push your change and modified to both repositories.

References

  • http://mcwitt.github.io/2015/04/29/jekyll_blogging_with_ipython3/
comments powered by Disqus