Skip to content

Commit

Permalink
Merge pull request #4 from scottyhq/website
Browse files Browse the repository at this point in the history
Add materials for creating a basic website
  • Loading branch information
scottyhq authored Jun 11, 2024
2 parents 092d454 + 868ae2c commit c6277fe
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/create_website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Deploy Website to GitHub Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
pages: write
id-token: write

jobs:
# Build Website
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Conda environment with Micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: website_figure/environment.yml
cache-environment: true

- name: Build Website
shell: bash -el {0}
run: |
jupyter nbconvert --execute --to html myfigure.ipynb
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: myfigure.html


# Publish Website to GitHub Pages if built successfully
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Setup Pages
uses: actions/configure-pages@v5

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
166 changes: 166 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
website_figure/*.html
website_figure/_build
*.bak
.DS_Store
.vscode

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
20 changes: 20 additions & 0 deletions website_figure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Turn a Jupyter Notebook into a public website

The basic idea is to *execute* a notebook and render both code and figures on a website

(nbconvert)[https://nbconvert.readthedocs.io] is a tool in the Jupyter ecosystem to convert .ipynb to various formats including HTML

We'll run this command
`jupyter nbconvert --execute --to html myfigure.ipynb`

Exercise 1: Explore the command line options to remove code cells https://nbconvert.readthedocs.io/en/latest/config_options.html#cli-flags-and-aliases

Exercise 2: Hide specific cells using cell metadata https://nbconvert.readthedocs.io/en/latest/removing_cells.html#removing-cells-inputs-or-outputs

## Other tools

If you plan on building a more sophisticated website, the pattern is the same! But definitely check out these tools that add a lot of functionality such as contents navigation, search, image/output management, cross-referencing, extended markdown features and nice styling just to name a few!

* https://mystmd.org
* https://jupyterbook.org
* https://quartopub.com
11 changes: 11 additions & 0 deletions website_figure/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: website
channels:
- conda-forge
dependencies:
- cartopy
- geoviews
- h5netcdf
- hvplot
- nbconvert
- pooch
- xarray
70 changes: 70 additions & 0 deletions website_figure/myfigure.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# My scientific results!\n",
"\n",
"Below is a figure generated in GitHub Actions and made public on the web"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import cartopy.crs as ccrs\n",
"import hvplot.xarray\n",
"import xarray as xr\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# https://tutorial.xarray.dev/fundamentals/04.3_geographic_plotting.html\n",
"# https://tutorial.xarray.dev/intermediate/hvplot.html\n",
"ds = xr.tutorial.open_dataset(\"air_temperature.nc\").rename({\"air\": \"Tair\"})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds.Tair.isel(time=1).hvplot(\n",
" projection=ccrs.Orthographic(-90, 30),\n",
" coastline=True,\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit c6277fe

Please sign in to comment.