Last active
May 17, 2016 15:41
-
-
Save lekaha/1c7e5e849d1ab5fd72fda44821296fda to your computer and use it in GitHub Desktop.
nbconvert config script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
from urllib.parse import quote # Py 3 | |
except ImportError: | |
from urllib2 import quote # Py 2 | |
import os | |
import sys | |
import datetime | |
fullname = None | |
f = None | |
for arg in sys.argv: | |
if arg.endswith('.ipynb'): | |
fullname = arg | |
f = fullname.split('.ipynb')[0] | |
break | |
c = get_config() | |
c.NbConvertApp.export_format = 'markdown' | |
c.MarkdownExporter.template_file = 'jekyll-post' | |
c.Exporter.file_extension = '.md' | |
def path2url(path): | |
"""Turn a file path into a URL""" | |
parts = path.split(os.path.sep) | |
print os.path.sep, parts | |
return '{{ site.baseurl }}/img/' + '/'.join(quote(part) for part in parts) | |
c.MarkdownExporter.filters = {'path2url': path2url} | |
if f: | |
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(fullname) | |
modified_date = datetime.datetime.fromtimestamp(mtime).strftime('%Y-%m-%d') | |
out_filename = modified_date + '-' + '-'.join(f.split()) + '.md' | |
c.NbConvertApp.output_base = out_filename | |
c.FilesWriter.build_directory = './' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment