Jupyter Notebook Integration
By Amr
Full Jupyter notebook support with GitHub Pages compatibility, automated conversion, and responsive design.
Estimated reading time: 4 minutes
Table of Contents
Jupyter Notebook Integration
The Zer0-Mistakes theme provides full Jupyter notebook support with GitHub Pages compatibility through automated pre-build conversion.
Overview
Key features:
- GitHub Pages Compatible: Uses pre-build conversion (no custom plugins)
- Automated Conversion: GitHub Actions workflow on push
- Rich Content: Code, equations, plots, tables, images
- Responsive Design: Bootstrap 5 styling
How It Works
graph LR
A[.ipynb File] --> B[nbconvert]
B --> C[Markdown + Images]
C --> D[Jekyll Build]
D --> E[HTML Page]
- Notebooks stored in
pages/_notebooks/ - Conversion script runs during build
- Markdown files generated with front matter
- Images extracted to
assets/images/notebooks/ - Jekyll renders final HTML
Quick Start
Add a Notebook
- Place
.ipynbfile inpages/_notebooks/:
pages/_notebooks/
├── data-analysis.ipynb
└── machine-learning-intro.ipynb
- Convert notebooks:
# Using Docker
docker-compose exec jekyll ./scripts/convert-notebooks.sh
# Or locally (requires nbconvert)
./scripts/convert-notebooks.sh
- View at
/notebooks/your-notebook-name/
Conversion Script
Basic Usage
# Convert all notebooks
./scripts/convert-notebooks.sh
# Dry run (preview only)
./scripts/convert-notebooks.sh --dry-run
# Force reconvert all
./scripts/convert-notebooks.sh --force
# List notebooks
./scripts/convert-notebooks.sh --list
What It Does
- Finds
.ipynbfiles inpages/_notebooks/ - Runs
jupyter nbconvert --to markdown - Extracts images to
assets/images/notebooks/ - Adds Jekyll front matter
- Creates collection entry
Notebook Layout
Notebooks use a specialized layout:
# _config.yml
defaults:
- scope:
path: "pages/_notebooks"
type: "notebooks"
values:
layout: "notebook"
permalink: /notebooks/:basename/
Layout Features
- Metadata display (author, date, kernel)
- Navigation between notebooks
- Download link to original
.ipynb - Comment integration
- Responsive tables and images
Styling
Code Cells
/* Input cells */
.notebook-input {
background: var(--bs-code-bg);
border-left: 3px solid var(--bs-primary);
padding: 1rem;
}
/* Output cells */
.notebook-output {
background: var(--bs-light);
border-left: 3px solid var(--bs-success);
padding: 1rem;
}
/* Execution count */
.notebook-prompt {
color: var(--bs-secondary);
font-family: monospace;
}
Tables
/* Dataframe tables */
.notebook-table {
overflow-x: auto;
}
.notebook-table table {
border-collapse: collapse;
width: 100%;
}
Images
/* Plot outputs */
.notebook-image img {
max-width: 100%;
height: auto;
}
MathJax Integration
Equations render automatically:
Inline Math:
The equation $E = mc^2$ is famous.
Block Math:
$$
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$
GitHub Actions
Automated Conversion
# .github/workflows/convert-notebooks.yml
on:
push:
paths:
- 'pages/_notebooks/**/*.ipynb'
jobs:
convert:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Convert notebooks
run: ./scripts/convert-notebooks.sh
- name: Commit changes
run: |
git add pages/_notebooks/*.md assets/images/notebooks/
git commit -m "Convert notebooks" || true
git push
Configuration
Jekyll Config
# _config.yml
collections:
notebooks:
output: true
permalink: /notebooks/:basename/
defaults:
- scope:
type: notebooks
values:
layout: notebook
mathjax: true
toc: true
Makefile Targets
# Convert all notebooks
convert-notebooks:
./scripts/convert-notebooks.sh
# Preview conversion
convert-notebooks-dry-run:
./scripts/convert-notebooks.sh --dry-run
Troubleshooting
Conversion Fails
- Check nbconvert is installed:
pip install nbconvert - Verify notebook is valid JSON
- Check for special characters in path
Images Not Showing
- Verify images extracted to
assets/images/notebooks/ - Check image paths in generated Markdown
- Rebuild Jekyll site
Math Not Rendering
- Ensure
mathjax: truein front matter - Check MathJax script loaded
- Verify equation syntax
Tables Overflow
Add responsive wrapper:
<div class="table-responsive">
</div>