• This repository has been archived on 07/Apr/2023
  • Stars
    star
    423
  • Rank 101,883 (Top 3 %)
  • Language
    Jupyter Notebook
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pelican plugin for blogging with Jupyter/IPython Notebooks

NOT MAINTAINED

  • I have not used this project myself on a long time
  • No issues or PRs can be created
  • I have moved on to mkdocs and my mkdocs-jupyter plugin and I recommend to do the same

pelican-jupyter: Pelican plugin for Jupyter Notebooks

pypi build coverage license

Installation

pip install pelican-jupyter

Pelican and Jupyter versions

The main focus is to run with the latest versions of the packages but there is a good chance the plugin will work correctly with older versions of Pelican and Jupyter/. The recommended version of libraries are:

  • pelican>=4
  • notebook>=6
  • nbconvert>=5

Usage

This plugin provides two modes to use Jupyter notebooks in Pelican:

  1. As a new markup language so .ipynb files are recognized as a valid filetype for an article
  2. As a liquid tag based on the liquid tags plugin so notebooks can be included in a regular post using Markdown (.md) files.

Mode A: Markup Mode

On your pelicanconf.py:

MARKUP = ("md", "ipynb")

from pelican_jupyter import markup as nb_markup
PLUGINS = [nb_markup]

IGNORE_FILES = [".ipynb_checkpoints"]

With this mode you need to pass the MD metadata to the plugins with one of this two options:

Option 1: .nbdata metadata file

Place the .ipynb file in the content folder and create a new file with the same name as the ipython notebook with extension .nbdata. For example if you have my_post.ipynb create my_post.nbdata.

The .nbdata should contain the metadata like a regular Markdown based article (note the empty line at the end, you need it):

Title:
Slug:
Date:
Category:
Tags:
Author:
Summary:

You can specify to only include a subset of notebook cells with the Subcells metadata item. It should contain the index (starting at 0) of first and last cell to include (use None for open range). For example, to skip the first two cells:

Subcells: [2, None]

Option 2: Metadata cell in notebook

With this option, the metadata is extracted from the first cell of the notebook (which should be a Markdown cell), this cell is then ignored when the notebook is rendered.

On your pelicanconf.py:

MARKUP = ("md", "ipynb")

from pelican_jupyter import markup as nb_markup
PLUGINS = [nb_markup]
IPYNB_MARKUP_USE_FIRST_CELL = True

IGNORE_FILES = [".ipynb_checkpoints"]

Now, you can put the metadata in the first notebook cell in Markdown mode, like this:

- title: My notebook
- author: John Doe
- date: 2018-05-11
- category: python
- tags: pip

Mode B: Liquid tags

On your pelicanconf.py:

MARKUP = ('md', )

from pelican_jupyter import liquid as nb_liquid
PLUGINS = [nb_liquid]

IGNORE_FILES = [".ipynb_checkpoints"]

After this you can use a liquid tag to include a notebook in any regular markdown article, for example mypost.md:

Title:
Slug:
Date:
Category:
Tags:
Author:
Summary:

{% notebook path/from/content/dir/to/notebook.ipynb %}

Recommend mode?

Personally I like Method A - Option 1 since I write the Notebooks first and then I just add the metadata file and keeps the notebook clean.

The Liquid tag mode provide more flexibility to combine an existing notebook code or output with extra text on a Markdown. You can also combine 2 or more notebooks in this mode. The only problem with the liquid tag mode is that it doesn't generate a summary for the article automatically from the notebook so you have to write it in the source .md file that includes the notebook.s

You can use both modes at the same time but you are probably going to see a exception that prevents conflicts, ignore it.

Note on CSS

If the notebooks look bad on your pelican theme this can help.

There is some issues/conflicts regarding the CSS that the Jupyter Notebook requires and the pelican themes.

I do my best to make the plugin work with every theme but for obvious reasons I cannot guarantee that it will look good in any pelican theme.

Jupyter Notebook is based on bootstrap so you probably will need your theme to be based on that it if you want the html and css to render nicely.

I try to inject only the necessary CSS by removing Jupyter's bootstrap code and only injecting the extra CSS code. In some cases but fixes are needed, I recommend looking at how my theme fixes them.

You can suppress the inclusion of any Notebook CSS entirely by setting IPYNB_SKIP_CSS=True, this allows more flexibility on the pelican theme.

The IPYNB_EXPORT_TEMPLATE option is another great way of extending the output natively using Jupyter nbconvert.

Settings

Note: If you are using the Liquid mode you need to set the variables like this inside the pelicanconf.py.

LIQUID_CONFIGS = (("IPYNB_EXPORT_TEMPLATE", "notebook.tpl", ""), )

If you are using the Markup mode then just add this variables to your pelicanconf.py.

Setting Description
IPYNB_FIX_CSS = True [markup and liquid] Do not apply any of the plugins "fixes" to the Jupyter CSS use all the default Jupyter CSS.
IPYNB_SKIP_CSS = False [markup and liquid] Do not include (at all) the notebook CSS in the generated output. This is usefull if you want to include it yourself in the theme.
IPYNB_PREPROCESSORS [markup and liquid] A list of nbconvert preprocessors to be used when generating the HTML output.
IPYNB_EXPORT_TEMPLATE [markup and liquid] Path to nbconvert export template (relative to project root). For example: Create a custom template that extends from the basic template and adds some custom CSS and JavaScript, more info here docs and example here.
IPYNB_STOP_SUMMARY_TAGS = [('div', ('class', 'input')), ('div', ('class', 'output')), ('h2', ('id', 'Header-2'))] [markup only] List of tuples with the html tag and attribute (python HTMLParser format) that are used to stop the summary creation, this is useful to generate valid/shorter summaries.
IPYNB_GENERATE_SUMMARY = True [markup only] Create a summary based on the notebook content. Every notebook can still use the sSummary from the metadata to overwrite this.
IPYNB_EXTEND_STOP_SUMMARY_TAGS [markup only] List of tuples to extend the default IPYNB_STOP_SUMMARY_TAGS.
IPYNB_NB_SAVE_AS [markup only] If you want to make the original notebook available set this variable in a is similar way to the default pelican ARTICLE_SAVE_AS setting. This will also add a metadata field nb_path which can be used in the theme. e.g. blog/{date:%Y}/{date:%m}/{date:%d}/{slug}/notebook.ipynb
IPYNB_COLORSCHEME [markup only] Change the pygments colorscheme used for syntax highlighting
IGNORE_FILES = ['.ipynb_checkpoints'] [Pelican setting useful for markup] Prevents pelican from trying to parse notebook checkpoint files.

Example template for IPYNB_EXPORT_TEMPLATE:

{%- extends 'basic.tpl' -%}

{% block header %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

<style type="text/css">
div.code_cell {
    border: 2px solid red;
}
</style>
{%- endblock header %}

More Repositories

1

word2vec

Python interface to Google word2vec
C
2,566
star
2

tsne

A python wrapper for Barnes-Hut tsne
C++
405
star
3

mkdocs-jupyter

Use Jupyter Notebook in mkdocs
Jupyter Notebook
375
star
4

jupyter-flex

Build dashboards using Jupyter Notebooks
JavaScript
315
star
5

s3contents

Jupyter Notebooks in S3 - Jupyter Contents Manager implementation
Python
244
star
6

copper

Fast, easy and intuitive machine learning prototyping.
Python
124
star
7

PythonFinance

basic Python Finance Package
Python
104
star
8

espn-nba-scrapy

NBA Data mining
Python
70
star
9

demucs-service

Use DEMUCS to split songs into multiple sources
Python
23
star
10

polyaxon-argo-seldon-example

Model management example using Polyaxon, Argo and Seldon
Python
23
star
11

demucs-app

Use DEMUCS to split songs into multiple sources
JavaScript
20
star
12

datasciencebox

Create and manage instances for data science
Python
20
star
13

danielfrg.com

Source for danielfrg.com
HTML
20
star
14

gcp-llm-retrieval-augmentation

A retrieval augmentation LLM demo in GCP
Jupyter Notebook
18
star
15

harvard-cs109-fall-2013

Harvard CS 109 - Data Science - Fall 2013
Python
14
star
16

jupyterhub-kubernetes_spawner

JupyterHub Kubernete Spawner
Python
14
star
17

django-hospital

Python
12
star
18

storm-sklearn

from zero to storm cluster for realtime classification using sklearn
Python
12
star
19

terraform-cloudera

Terraform module for Cloudera Manager
HCL
11
star
20

illusionist

Interactive client-only reports based on Jupyter Notebooks and Jupyter widgets.
Python
11
star
21

docker-conda-repo

Docker container for creating and serving a custom conda repo/channel
Python
11
star
22

docker-selenium

docker-selenium
Jupyter Notebook
11
star
23

salt-conda

Salt states for Continuum Analytics conda python package manager
Python
9
star
24

django_crawler

A django blog crawler
Python
9
star
25

kaggle-word2vec

Kaggle word2vec NLP tutorial
Python
8
star
26

sublime-open

Open files quicker and easier: Dynamic browsing or a static list of files
Python
7
star
27

semafor-parsing

Parsing web content on SEMAFOR at scale using salt and celery
Python
6
star
28

coursera-comp-for-data-analysis

Coursera Computing for Data Analysis - Fall 2012
R
5
star
29

kaggle-yelp-recruiting-competition

Python
5
star
30

nbviewer.js

Render Jupyter Notebooks in the browser using only JS
JavaScript
5
star
31

remote-pip

Install pip packages in remote hosts
Python
4
star
32

web-template-go-react

Template for Go + React + TS
Go
3
star
33

reproduceit-538-baltimore-black-income

ReproduceIt: How Baltimoreโ€™s Young Black Men Are Boxed In
3
star
34

kaggle-bulldozers

Python
3
star
35

spark-plot

Simplifies plotting Spark DataFrames by making calculations for plots inside Spark
Jupyter Notebook
3
star
36

github-archive

The simplest script to make an archive of a Github user/org
Shell
3
star
37

kaggle-data-science-london

Python
3
star
38

coursera-data-analysis

Coursera Data Analysis - Fall 2012
Python
2
star
39

docker-multicorn

Hello world of multicorn in a docker container
Shell
2
star
40

newtask

Desktop python app to create new tasks on major task management web apps
Python
2
star
41

atom-nbviewer

Atom plugin to preview Jupyter Notebooks
JavaScript
2
star
42

docker-rpi2xc

Docker container to cross-compile for the rpi2
CMake
1
star
43

ec2hosts

Update /etc/hosts from ec2 instances
Python
1
star
44

pydata-nyc-2015

PyData NYC 2015
HTML
1
star
45

awesome-google-ads-api

A curated list of awesome Google Ads API resources
1
star
46

actions-dashboard

Dashboard for my GitHub Actions
1
star
47

remote-conda

Install conda packages in remote hosts
Go
1
star
48

cyhdfs3

Cython based wrapper for libhdfs3
Python
1
star
49

adsctl

Google Ads Control CLI and prompt
Python
1
star
50

ml-notes

Personal tools and notebooks for machine learning
Jupyter Notebook
1
star
51

grpc-up-and-running

Rust
1
star
52

atom-lighttable-syntax

An attempt of a Light Table syntax theme for atom
CSS
1
star
53

kaggle-salt

https://www.kaggle.com/c/tgs-salt-identification-challenge
Jupyter Notebook
1
star
54

reproduceit-538-adam-sandler-movies

ReproduceIt: The Three Types Of Adam Sandler Movies
1
star
55

django-ddns

Django DDNS app using AppFog as Paas.
Python
1
star
56

coursera-computational-investing-part-I

Computational Investing Part I - Fall 2012
1
star