When you host Jupyter notebooks (.ipynb files) on GitHub Pages, visitors see raw JSON instead of rendered notebooks because:
- GitHub.com vs GitHub Pages: GitHub's website has special rendering for
.ipynbfiles, but GitHub Pages is just a static file server - JSON Format: Notebooks are JSON files containing code, markdown, and outputs - browsers don't know how to render this nicely
- No Dynamic Processing: GitHub Pages can't run Python/JavaScript to convert notebooks on-the-fly
Best for: Quick sharing, no setup required
[View Notebook](https://nbviewer.org/github/username/repository/blob/main/path/notebook.ipynb)Pros:
- No conversion needed
- Always up-to-date
- Perfect rendering
Cons:
- External dependency
- Requires internet
- Not customizable
Best for: Professional portfolios, custom styling, self-hosted solutions
Pros:
- Complete control over styling
- Fast loading
- Works offline
- SEO friendly
- Professional appearance
Cons:
- Requires conversion process
- Larger file sizes
- Need to update when notebooks change
-
Professional Presentation
- Clean, consistent styling
- Custom CSS for branding
- Better typography and layout
-
Performance Benefits
- Faster loading than raw notebooks
- Better mobile experience
- Optimized for web viewing
-
SEO and Accessibility
- Search engines can index content
- Screen readers can navigate properly
- Better semantic structure
-
Portfolio Integration
- Seamless integration with your existing
index.html - Consistent navigation and branding
- Easy to link between projects
- Seamless integration with your existing
pip install nbconvertpython convert_notebooks_to_html.py- Finds all notebooks in your repository
- Converts each to HTML maintaining directory structure
- Generates an index page with organized links
- Extracts titles from notebook metadata or content
- Creates navigation between original and HTML versions
html_notebooks/
├── Data_Analysis/
│ ├── automobile-data-wrangling-cleaning.html
│ ├── car-price-model-development.html
│ └── ...
├── ML/
│ ├── Classification/
│ │ └── ...
│ └── Regression/
│ └── ...
└── ...
notebook_index.html # Generated index page
Add links to the HTML versions in your existing index.html:
<div class="notebook-section">
<h2>📊 Data Science Notebooks</h2>
<p><a href="notebook_index.html">View All Notebooks (HTML)</a></p>
<!-- Featured notebooks -->
<div class="featured-notebooks">
<a href="html_notebooks/Data_Analysis/car-price-model-development.html">
Car Price Prediction Model
</a>
<a href="html_notebooks/Capstone_Data_Science_SpaceY/spacex-machine-learning-prediction.html">
SpaceX Launch Prediction
</a>
</div>
</div>For automatic conversion on each commit, create .github/workflows/convert-notebooks.yml:
name: Convert Notebooks to HTML
on:
push:
paths:
- '**/*.ipynb'
workflow_dispatch:
jobs:
convert:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
pip install nbconvert
- name: Convert notebooks
run: python convert_notebooks_to_html.py
- name: Commit HTML files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add html_notebooks/ notebook_index.html
git commit -m "Auto-update notebook HTML versions" || exit 0
git push- Original
.ipynb: For development and collaboration - HTML version: For public viewing and portfolios
- Use descriptive titles in notebooks
- Maintain consistent directory structure
- Add README files for context
- Modify the CSS in the conversion script
- Match your portfolio's branding
- Ensure mobile responsiveness
- Use relative links where possible
- Optimize images in notebooks
- Consider lazy loading for large notebooks
- nbconvert not found: Install with
pip install nbconvert - Conversion fails: Check for syntax errors in notebooks
- Missing outputs: Re-run notebooks before conversion
- Large files: Consider splitting complex notebooks
If conversion fails for specific notebooks:
- Check the error message in the script output
- Manually fix problematic notebooks
- Re-run the conversion script
For more complex documentation:
pip install jupyter-book
jupyter-book build .For interactive presentations:
pip install voila
voila notebook.ipynb --no-browser- Hugo: With notebook plugins
- Jekyll: GitHub Pages native
- Sphinx: Python documentation standard
Converting notebooks to HTML provides the best experience for portfolio visitors while maintaining the flexibility of Jupyter notebooks for development. The conversion script automates this process and creates a professional presentation of your data science work.