Skip to content

Instantly share code, notes, and snippets.

@maclandrol maclandrol/jekyll.py
Created Jan 10, 2016

Embed
What would you like to do?
# modification of config created here: https://gist.github.com/cscorley/9144544
try:
from urllib.parse import quote # Py 3
except ImportError:
from urllib2 import quote # Py 2
import os
import sys
from settings import template_path, template_file, build_dir, rel_img_path
f = None
for arg in sys.argv:
if arg.endswith('.ipynb'):
f = arg.split('.ipynb')[0]
break
c = get_config()
c.NbConvertApp.export_format = 'markdown'
c.MarkdownExporter.template_path = [template_path] # point this to your jekyll template file
c.MarkdownExporter.template_file = template_file
#c.Application.verbose_crash=True
# modify this function to point your images to a custom path
# by default this saves all images to a directory 'images' in the root of the blog directory
def path2support(path):
"""Turn a file path into a URL"""
print '{{ site.baseurl }}'+ quote(os.path.join(rel_img_path, path))
return '{{ site.baseurl }}'+ quote(os.path.join(rel_img_path, path))
c.MarkdownExporter.filters = {'path2support': path2support}
if f:
c.NbConvertApp.output_base = os.path.basename(f).lower().replace(' ', '-')
c.FilesWriter.build_directory = build_dir # point this to your build directory
{% extends 'markdown.tpl' %}
{%- block header -%}
---
layout: post
title: "{{resources['metadata']['name']}}"
tags:
- python
- notebook
---
{%- endblock header -%}
{% block in_prompt %}
**In [{{ cell.execution_count }}]:**
{% endblock in_prompt %}
{% block output_prompt %}
{%- endblock output_prompt %}
{% block input %}
{{ '{% highlight python %}' }}
{{ cell.source }}
{{ '{% endhighlight %}' }}
{% endblock input %}
{% block pyerr %}
{{ super() }}
{% endblock pyerr %}
{% block traceback_line %}
{{ line | indent | strip_ansi }}
{% endblock traceback_line %}
{% block pyout %}
{% block data_priority scoped %}
{{ super() }}
{% endblock %}
{% endblock pyout %}
{% block data_svg %}
![svg]({{ output.metadata.filenames['image/svg+xml'] | path2support }})
{% endblock data_svg %}
{% block data_png %}
![png]({{ output.metadata.filenames['image/png'] | path2support }})
{% endblock data_png %}
{% block data_jpg %}
![jpeg]({{ output.metadata.filenames['image/jpeg'] | path2support }})
{% endblock data_jpg %}
{% block markdowncell scoped %}
{{ cell.source | wrap_text(80) }}
{% endblock markdowncell %}
{% block headingcell scoped %}
{{ '#' * cell.level }} {{ cell.source | replace('\n', ' ') }}
{% endblock headingcell %}
{% block unknowncell scoped %}
unknown type {{ cell.type }}
{% endblock unknowncell %}
#template directory
template_path ='/home/manu/.ipython/templates'
#template file
template_file = 'jekyll'
#build directory
build_dir = '/home/manu/Documents/Projects/Programmation/GithubRepos/maclandrol.github.io/_drafts'
#relative image folder path (to blog root)
rel_img_path = '/public/images/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.