Skip to main content

Jupyter Notebook Integration for Jekyll

Overview

This implementation adds full Jupyter notebook support to the Zer0-Mistakes Jekyll theme with GitHub Pages compatibility. Notebooks are converted to Jekyll-compatible Markdown files during the build process, maintaining all formatting, code blocks, outputs, and mathematical equations.

🎯 Key Features

GitHub Pages Compatible - Uses pre-build conversion (no custom plugins)
Automated Conversion - GitHub Actions workflow converts notebooks on push
Manual Control - Makefile targets for local conversion
Rich Content Support - Code, equations, plots, tables, and images
Responsive Design - Bootstrap 5 styling with mobile-first layout
SEO Optimized - Proper front matter and Schema.org markup
MathJax Integration - LaTeX equation rendering (already configured)

📁 Implementation Components

1. Docker Environment (docker/Dockerfile)

2. Conversion Script (scripts/convert-notebooks.sh)

3. Notebook Layout (_layouts/notebook.html)

4. Notebook Styling (_sass/notebooks.scss)

5. Jekyll Configuration (_config.yml)

6. Makefile Targets

7. GitHub Actions (.github/workflows/convert-notebooks.yml)

🚀 Usage

Local Development

1. Add a Notebook

Place your .ipynb file in pages/_notebooks/:

cp my-notebook.ipynb pages/_notebooks/

2. Convert Notebook

# Preview what will be converted
make convert-notebooks-dry-run

# Convert the notebook
make convert-notebooks

# Or use the script directly
./scripts/convert-notebooks.sh

3. View Results

The converted Markdown file appears at:

Extracted images go to:

Docker Development

Rebuild Container with Python/Jupyter

docker-compose down
docker-compose up --build

Convert Notebooks in Container

docker-compose exec jekyll ./scripts/convert-notebooks.sh

Automatic Conversion (GitHub Actions)

When you push .ipynb files to GitHub:

  1. Push notebook to main/develop branch
    git add pages/_notebooks/my-notebook.ipynb
    git commit -m "Add new notebook"
    git push
    
  2. GitHub Actions automatically:
    • Converts the notebook to Markdown
    • Extracts images
    • Commits converted files
    • Pushes changes back
  3. Jekyll builds the site with converted Markdown

Manual Force Reconversion

To reconvert all notebooks (useful after styling changes):

# Locally
make convert-notebooks-force

# Via GitHub Actions (manual trigger)
# Go to Actions > Convert Jupyter Notebooks > Run workflow
# Enable "force_reconvert" option

📝 Front Matter

Notebooks are converted with Jekyll front matter extracted from:

  1. Notebook metadata (if present)
  2. First markdown cell starting with #
  3. Filename (as fallback)

Example generated front matter:

---
title: "My Notebook Title"
description: "Jupyter notebook"
layout: notebook
collection: notebooks
date: 2025-11-29T10:00:00.000Z
categories: [Notebooks]
tags: [jupyter, python]
comments: true
jupyter_metadata: true
lastmod: 2025-11-29T10:00:00.000Z
---

🎨 Customization

Modify Notebook Styling

Edit _sass/notebooks.scss to customize:

Change Conversion Behavior

Edit scripts/convert-notebooks.sh to modify:

Customize Layout

Edit _layouts/notebook.html to change:

📊 Test Notebook

A sample notebook is included at pages/_notebooks/test-notebook.ipynb demonstrating:

To test the full pipeline:

make convert-notebooks
# View the converted file at pages/_notebooks/test-notebook.md

🔧 Troubleshooting

Notebook Won’t Convert

Check dependencies:

python3 --version
python3 -c "import nbconvert" && echo "✓ nbconvert installed"

Install if missing:

pip3 install jupyter nbconvert

Images Not Displaying

Check image paths in converted Markdown:

grep -r "!\[" pages/_notebooks/*.md

Verify images exist:

ls -R assets/images/notebooks/

Fix paths if needed: The conversion script should use Jekyll-compatible paths:

![Image](/assets/images/notebooks/my-notebook_files/image.png)

Conversion Fails in Docker

Rebuild container with Python:

docker-compose down
docker-compose build --no-cache
docker-compose up

Check Python installation in container:

docker-compose exec jekyll python3 --version
docker-compose exec jekyll pip3 list | grep nbconvert

GitHub Actions Not Running

Check workflow triggers:

Manual trigger: Go to GitHub Actions > Convert Jupyter Notebooks > Run workflow

LaTeX Equations Not Rendering

MathJax is already configured in _includes/core/head.html

If equations don’t render:

  1. Check browser console for MathJax errors
  2. Verify equations use proper LaTeX syntax
  3. Ensure MathJax script loads before content

📚 Additional Resources

nbconvert Documentation

Jekyll Collections

MathJax Documentation

🔄 Future Enhancements

Potential improvements for future versions:

  1. Interactive Widgets - Explore client-side rendering options
  2. Notebook Metadata - Extract more detailed kernel/execution info
  3. Version Control - Track notebook changes and show diffs
  4. Search Integration - Index notebook content for site search
  5. Code Folding - Collapsible code cells for long notebooks
  6. Execution in Browser - JupyterLite integration for live execution
  7. NBViewer Fallback - Link to NBViewer for complex notebooks

📄 Files Modified/Created

Created Files

Modified Files

✅ Implementation Complete

All components are in place for full Jupyter notebook support:

  1. ✅ Docker environment with Python/nbconvert
  2. ✅ Conversion script with comprehensive options
  3. ✅ Dedicated notebook layout with Bootstrap 5
  4. ✅ Custom SCSS styling for notebooks
  5. ✅ Jekyll configuration for notebooks collection
  6. ✅ Makefile targets for manual control
  7. ✅ GitHub Actions for automatic conversion
  8. ✅ Test notebook with sample content

Next step: Push to GitHub to trigger the automated conversion workflow!

git add .
git commit -m "feat: add Jupyter notebook rendering support

- Add Python/nbconvert to Docker environment
- Create notebook conversion script with image extraction
- Add dedicated notebook layout extending default.html
- Implement notebook-specific SCSS styling
- Configure notebooks collection in Jekyll
- Add Makefile targets for manual conversion
- Set up GitHub Actions for automatic conversion
- Include test notebook with sample content

Supports GitHub Pages deployment via pre-build conversion"

git push origin main

🎉 Success Criteria

Your implementation is working correctly if:

Congratulations! Your Jekyll site now supports Jupyter notebooks! 🎊