Deploy your Nikola-powered blog content from the IPython notebook

  |   Source   |   Minimap

Following the idea to release all the extensions I had working on in the last few weeks/months, today I will release an old but very useful IPython notebook extension for people blogging with Nikola: the nikola_deploy extension.

Yes, I am always very original picking the names of the extensions ;-). A pic to illustrate the extension button at the toolbar:

Note: Nikola supports the ipynb file as an input... and using the IPython.nbconvert machinery it is able to render the static HTML representation of your ipynbs inside the complete infrastructure of a powerful static site engine.

First, to know some things about my blogging workflow using IPython, Nikola, git and gh-pages, I suggest you to re-read these previous posts:

OK, coming back to the extension, the idea behind this one is very simple: I will call the nikola deploy command from inside the IPython notebook using our beloved IPython.notebook.kernel.execute method, and also taking the advantage of passing commands to the underlying system just pre-pending with the ! mark. The relevant lines are below:

36    if (clean=="True") {
37      IPython.notebook.kernel.execute('!nikola clean');
38    }
39    IPython.notebook.kernel.execute('!nikola build');
40    IPython.notebook.kernel.execute('!nikola deploy');

After writing the content of my post following the workflow explained in previous posts, I just click on the nikola_deploy extension button and the site is cleaned (if you choose this option to True in the config file, please set it to False if you want a quick building), built and deployed automagically ;-)

And that's all... the complete code below:

In [1]:
cat -n /media/datos/Desarrollos/mIPyex/custom/nikola_deploy/main.js
  Click me to hide the output
     1	/*
     2	* ----------------------------------------------------------------------------
     3	* Copyright (c) 2013 - Damián Avila
     4	*
     5	* Distributed under the terms of the Modified BSD License.
     6	*
     7	* A little extension to deploy a nikola site/blog from the IPython notebook.
     8	* -----------------------------------------------------------------------------
     9	*/
    10	
    11	function messager() {
    12	  var message = $('<div/>').append(
    13	                  $("<p/></p>").addClass('dialog').html(
    14	                    "Your ipynb-based site/blog post is being deployed now..."
    15	                    )
    16	                ).append(
    17	                  $("<p/></p>").addClass('dialog').html(
    18	                    "We clean (configurable), build and deploy your Nikola " +
    19	                    "site/blog for you!"
    20	                    )
    21	                );
    22	
    23	  IPython.dialog.modal({
    24	    title : "Nikola deployment",
    25	    body : message,
    26	    buttons : {
    27	        OK : {class: "btn-danger"}
    28	    }
    29	  });
    30	
    31	}
    32	
    33	function nikolaDeploy(path, clean) {
    34	  IPython.notebook.kernel.execute('%bookmark root');
    35	  IPython.notebook.kernel.execute('%cd ' + path);
    36	  if (clean=="True") {
    37	    IPython.notebook.kernel.execute('!nikola clean');
    38	  }
    39	  IPython.notebook.kernel.execute('!nikola build');
    40	  IPython.notebook.kernel.execute('!nikola deploy');
    41	  IPython.notebook.kernel.execute('%cd -b root');
    42	  messager();
    43	}
    44	
    45	define(function() {
    46	  return {
    47	    parameters: function setup(param1, param2) {
    48	      IPython.toolbar.add_buttons_group([
    49	        {
    50	        'label'   : 'Deploy Nikola site/blog',
    51	        'icon'    : 'icon-upload-alt',
    52	        'callback': function(){nikolaDeploy(param1, param2)},
    53	        'id'      : 'start_nikola_deploy'
    54	        },
    55	      ])
    56	    }
    57	  }
    58	});

Again, the extension lives in this new repo: mIPyex, where I will upload the development versions of my own extensions. When I get them enough stable, I will make a copy of them in the IPython notebook extensions repo where you can get a lot of and useful interesting extensions.

OK, as you can see... it is very simple to blog with IPython and Nikola, so I invite you to try it now and let me know any ideas, comments or critics.

Enjoy!

Damián

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