Blogging with Nikola and IPython

  |   Source   |   Minimap

Alert! This post is outdated, please goto ;-) this link to get updated information.

NOTE: Obviously, this post was written in the IPython notebook and was rendered by Nikola (helped by nbconvert).

INGREDIENTS:

NOTE: The theme was tested with Nikola version 5.1

STEPS:

  • Install Nikola and IPython (probably you have IPython installed if you are reading this post).
  • Install the site-ipython theme in your Nikola instalation. You can see some the documentation about how to do it here.

NOTE: Another way to do it is copying the site-ipython theme inside the nikola/data/themes folder BEFORE installing Nikola.

NOTE2: The recommended way to do it would be copying the site-ipython theme inside your_site after initialization of your_site. See below.

  • Initialize your_site:

nikola init your_site

you can ask for

nikola --help

for other available options.

  • Create a plugins folder inside your_site
  • Copy the compile_ipynb plugin (compile_ipynb.plugin file and the compile_ipynb folder, which are is located inside the extra-plugins folder in the Nikola master) in your_site/plugins/ folder.
  • Then, download the custom nbconvert and nbformat from here and put them inside your_site/plugins/compile_ipynb/ folder.
  • Finally, you have to put:
post_pages = (
    ("posts/*.ipynb", "posts", "post.tmpl", True),
    ("stories/*.ipynb", "stories", "story.tmpl", False),
)

and

THEME = 'site-ipython'

in your conf.py file of your_site (you can modified the other pieces inside conf.py according to your needs).

NOTE: This setup is done only once time a life... hehe

USE:

  • First create a new post:

nikola new_post -f ipynb

NOTE: IGNORE the -2 option in nikola new_page (it is no sense with the current implementation).

You will be asked for a title (you can also add the title and tags in the previous call).

Then, two files will be created by Nikola in the /posts folder of your_site: a meta file containing title, slug, time, tags (you can modified them with any text processor) and a naive ipynb file with the corresponding title.

You can init the ipython notebook inside this folder and modified the "post" notebook as you wish (do not forget to save the changes inside your notebook).

  • Finally, just:

nikola build

and deploy the output folder containing your_site... to see it locally:

nikola serve

That's it all, my friend!

If you have any doubt, just tell me: @damianavila

Cheers,

Damián

PS: And now some cells to show you this is areal notebook...

In [1]:
pwd
  Click me to hide the output
Out[1]:
u'/home/damian/Desarrollos/To_PR/SITIOS/Damian_blog_nikola/posts'
In [2]:
%pylab inline
  Click me to hide the output
Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.
In [3]:
x = linspace(0, 3*pi, 500)
plot(x, sin(x**2))
title('A simple chirp');
  Click me to hide the output
In [4]:
x = 1
y = 4
z = y/(1-x)
  Click me to hide the output
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-4-dc39888fd1d2> in <module>()
      1 x = 1
      2 y = 4
----> 3 z = y/(1-x)

ZeroDivisionError: integer division or modulo by zero

Courtesy of MathJax, you can include mathematical expressions both inline: $e^{i\pi} + 1 = 0$ and displayed:

$$e^x=\sum_{i=0}^\infty \frac{1}{i!}x^i$$
In [5]:
from IPython.display import Image
Image(url='http://python.org/images/python-logo.gif')
  Click me to hide the output
Out[5]:
In [6]:
from IPython.display import YouTubeVideo
# a talk about IPython at Sage Days at U. Washington, Seattle.
# Video credit: William Stein.
YouTubeVideo('1j_HxD4iLn8')
  Click me to hide the output
Out[6]:

OK, enough... see you soon!

Did you like the content? Great!

Or visit my support page for more information.


Btw, don't forget this blog post is an ipynb file itself! So, you can download it from the "Source" link at the top of the post if you want to play with it ;-)

Comments powered by Disqus