How To Use Jupyter Notebook As Hugo Blog Post

  1. The first cell in the notebook should be a markdown cell with a Hugo header. Example:

    title: "How To use Jupyter Notebook As Hugo Blog Post"
    date: 2020-04-10
    tags: ["data science", "machine learning", "hugo"]
    draft: false
  2. Write all your python code and markdown annotations in the Notebook as normal

  3. Once done, remember one can individually select if a cell will be exported to Markdown or not by clicking the wrench on the side “Notebook Tools” and selecting a different “Raw NBConvert Format”

  4. At the end of the notebook, call the following command to convert the notebook to markdown !jupyter nbconvert --to markdown Untitled.ipynb

  5. (This step may be skipped if you have no figures) Move the files directory that is created, which holds images, so the Hugo blog post can render the images using this command

    !mv path/to/content/directory/
    !cp -r Untitled_files path/to/static/directory

    which requires one to install this package $ pip install jupyter_contrib_nbextensions

And after writing this, I forgot that I’ve used the hugo jupyter package in the past to achieve the same thing. Leaving this post up for historical and documentation reasons