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:
- 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.
- 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 .
hupyter.py does: #
- Solve mathjax problems. For detailes, see here .
- Move the auto-generated files by nbconvert
- Update image links in the output markdown file.
How to use
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
python hupyter.py notebooks/2022-08-24-hierarchical-clustering.ipynb en/blog
Last modified on 2022-08-28