Automatically convert Jupyter notebooks to Markdown
gcushen opened this issue · comments
Use the Python nbconvert module to clean up Jupyter notebooks and import them as blog posts.
Algo idea:
- Recursively locate all Jupyter notebooks in a site's
notebooks/
folder - Parse each notebook into a Markdown page bundle within
content/post/
folder usingnbconvert
's Python function- defaults to the h1 heading (falling back to filename) as the Hugo page
title
, and the conversion date fordate
If the first cell is Jupyter 'raw' type and begins with---
(YAML) use it as the page's front matter and hide that cell from the output- Fetch front matter options from notebook metadata field
- defaults to the h1 heading (falling back to filename) as the Hugo page
Tests:
- Add a unit test on a Jupyter notebook and check the Markdown output
I've worked with nbconvert
in the past. However, are we to assume that exports should be done as-is, or would there be an intent to integrate some use-defined way to allow for things like the RemoveTagsPreprocessor
to be used?
@ionlights thanks - I've updated the rough WIP algo above. Initially, lets keep it simple and only remove the first cell if it contains raw YAML front matter.