generated from fastai/fastpages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nb2post.py
executable file
·22 lines (18 loc) · 941 Bytes
/
nb2post.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Converts Jupyter Notebooks to Jekyll compliant blog posts"""
from datetime import datetime
import re, os, logging
from nbdev import export2html
from nbdev.export2html import Config, Path, _to_html, _re_block_notes
from fast_template import rename_for_jekyll
warnings = set()
# Modify the naming process such that destination files get named properly for Jekyll _posts
def _nb2htmlfname(nb_path, dest=None):
fname = rename_for_jekyll(nb_path, warnings=warnings)
if dest is None: dest = Config().doc_path
return Path(dest)/fname
# TODO: Open a GitHub Issue in addition to printing warnings
for original, new in warnings:
print(f'{original} has been renamed to {new} to be complaint with Jekyll naming conventions.\n')
## apply monkey patches
export2html._nb2htmlfname = _nb2htmlfname
export2html.notebook2html(fname='_notebooks/*.ipynb', dest='_posts/', template_file='/fastpages/fastpages.tpl', execute=False)