Hupyter: Convert Jupyter Notebooks to Hugo Posts

Hongtao Hao / 2022-08-28

Please refer to the documentation of hupyter repo .

I love writing tutorials in Jupyter Notebooks and I want to convert them to Hugo posts on my blog . I tried nb2hugo by vlunot but it lacks two functions:

  1. It seems that if I’ve converted it before, then I have to delete the converted blog posts in /content/ before I can convert again.
  2. It does not update the image path automatically. I have to manually update the image path.

These two deficiencies are pretty annoying because sometimes I need to modify my Jupyter notebooks and convert anew. Every time I convert, I have to delete the original blog post and manually change the image path.

I cannot bear it anymore so I wrote my own program to do the job. This, in fact, is not difficult at all! It only contains fewer than 60 lines in Python. The heaviest part has already been done by nbconvert , which is based on pandoc .

What hupyter.py does: #

How to use hupyter.py #

Copy the hupyter.py file and paste it to the root folder of your Hugo project. Then, at the root directory of your hugo project

python hupyter.py notebook_directory post_direction

An example:

python hupyter.py notebooks/2022-08-24-hierarchical-clustering.ipynb en/blog
#tutorial

Last modified on 2022-08-28