Skip to content

Commit c6277fe

Browse files
authored
Merge pull request #4 from scottyhq/website
Add materials for creating a basic website
2 parents 092d454 + 868ae2c commit c6277fe

File tree

5 files changed

+326
-0
lines changed

5 files changed

+326
-0
lines changed

.github/workflows/create_website.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Deploy Website to GitHub Pages
2+
3+
on:
4+
# Runs on pushes targeting the default branch
5+
push:
6+
branches: ["main"]
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
permissions:
13+
pages: write
14+
id-token: write
15+
16+
jobs:
17+
# Build Website
18+
build:
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
shell: bash -l {0}
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Install Conda environment with Micromamba
28+
uses: mamba-org/setup-micromamba@v1
29+
with:
30+
environment-file: website_figure/environment.yml
31+
cache-environment: true
32+
33+
- name: Build Website
34+
shell: bash -el {0}
35+
run: |
36+
jupyter nbconvert --execute --to html myfigure.ipynb
37+
38+
- name: Upload artifact
39+
uses: actions/upload-pages-artifact@v3
40+
with:
41+
path: myfigure.html
42+
43+
44+
# Publish Website to GitHub Pages if built successfully
45+
deploy:
46+
needs: build
47+
if: github.ref == 'refs/heads/main'
48+
runs-on: ubuntu-latest
49+
environment:
50+
name: github-pages
51+
url: ${{ steps.deployment.outputs.page_url }}
52+
53+
steps:
54+
- name: Setup Pages
55+
uses: actions/configure-pages@v5
56+
57+
- name: Deploy to GitHub Pages
58+
id: deployment
59+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
website_figure/*.html
2+
website_figure/_build
3+
*.bak
4+
.DS_Store
5+
.vscode
6+
7+
# Byte-compiled / optimized / DLL files
8+
__pycache__/
9+
*.py[cod]
10+
*$py.class
11+
12+
# C extensions
13+
*.so
14+
15+
# Distribution / packaging
16+
.Python
17+
build/
18+
develop-eggs/
19+
dist/
20+
downloads/
21+
eggs/
22+
.eggs/
23+
lib/
24+
lib64/
25+
parts/
26+
sdist/
27+
var/
28+
wheels/
29+
share/python-wheels/
30+
*.egg-info/
31+
.installed.cfg
32+
*.egg
33+
MANIFEST
34+
35+
# PyInstaller
36+
# Usually these files are written by a python script from a template
37+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
38+
*.manifest
39+
*.spec
40+
41+
# Installer logs
42+
pip-log.txt
43+
pip-delete-this-directory.txt
44+
45+
# Unit test / coverage reports
46+
htmlcov/
47+
.tox/
48+
.nox/
49+
.coverage
50+
.coverage.*
51+
.cache
52+
nosetests.xml
53+
coverage.xml
54+
*.cover
55+
*.py,cover
56+
.hypothesis/
57+
.pytest_cache/
58+
cover/
59+
60+
# Translations
61+
*.mo
62+
*.pot
63+
64+
# Django stuff:
65+
*.log
66+
local_settings.py
67+
db.sqlite3
68+
db.sqlite3-journal
69+
70+
# Flask stuff:
71+
instance/
72+
.webassets-cache
73+
74+
# Scrapy stuff:
75+
.scrapy
76+
77+
# Sphinx documentation
78+
docs/_build/
79+
80+
# PyBuilder
81+
.pybuilder/
82+
target/
83+
84+
# Jupyter Notebook
85+
.ipynb_checkpoints
86+
87+
# IPython
88+
profile_default/
89+
ipython_config.py
90+
91+
# pyenv
92+
# For a library or package, you might want to ignore these files since the code is
93+
# intended to run in multiple environments; otherwise, check them in:
94+
# .python-version
95+
96+
# pipenv
97+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
98+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
99+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
100+
# install all needed dependencies.
101+
#Pipfile.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
110+
# pdm
111+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112+
#pdm.lock
113+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114+
# in version control.
115+
# https://pdm.fming.dev/#use-with-ide
116+
.pdm.toml
117+
118+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
119+
__pypackages__/
120+
121+
# Celery stuff
122+
celerybeat-schedule
123+
celerybeat.pid
124+
125+
# SageMath parsed files
126+
*.sage.py
127+
128+
# Environments
129+
.env
130+
.venv
131+
env/
132+
venv/
133+
ENV/
134+
env.bak/
135+
venv.bak/
136+
137+
# Spyder project settings
138+
.spyderproject
139+
.spyproject
140+
141+
# Rope project settings
142+
.ropeproject
143+
144+
# mkdocs documentation
145+
/site
146+
147+
# mypy
148+
.mypy_cache/
149+
.dmypy.json
150+
dmypy.json
151+
152+
# Pyre type checker
153+
.pyre/
154+
155+
# pytype static type analyzer
156+
.pytype/
157+
158+
# Cython debug symbols
159+
cython_debug/
160+
161+
# PyCharm
162+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
163+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
164+
# and can be added to the global gitignore or merged into this file. For a more nuclear
165+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
166+
#.idea/

website_figure/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Turn a Jupyter Notebook into a public website
2+
3+
The basic idea is to *execute* a notebook and render both code and figures on a website
4+
5+
(nbconvert)[https://nbconvert.readthedocs.io] is a tool in the Jupyter ecosystem to convert .ipynb to various formats including HTML
6+
7+
We'll run this command
8+
`jupyter nbconvert --execute --to html myfigure.ipynb`
9+
10+
Exercise 1: Explore the command line options to remove code cells https://nbconvert.readthedocs.io/en/latest/config_options.html#cli-flags-and-aliases
11+
12+
Exercise 2: Hide specific cells using cell metadata https://nbconvert.readthedocs.io/en/latest/removing_cells.html#removing-cells-inputs-or-outputs
13+
14+
## Other tools
15+
16+
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!
17+
18+
* https://mystmd.org
19+
* https://jupyterbook.org
20+
* https://quartopub.com

website_figure/environment.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: website
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- cartopy
6+
- geoviews
7+
- h5netcdf
8+
- hvplot
9+
- nbconvert
10+
- pooch
11+
- xarray

website_figure/myfigure.ipynb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# My scientific results!\n",
8+
"\n",
9+
"Below is a figure generated in GitHub Actions and made public on the web"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"import cartopy.crs as ccrs\n",
19+
"import hvplot.xarray\n",
20+
"import xarray as xr\n",
21+
"import warnings\n",
22+
"warnings.filterwarnings('ignore')"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": null,
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"# https://tutorial.xarray.dev/fundamentals/04.3_geographic_plotting.html\n",
32+
"# https://tutorial.xarray.dev/intermediate/hvplot.html\n",
33+
"ds = xr.tutorial.open_dataset(\"air_temperature.nc\").rename({\"air\": \"Tair\"})"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": null,
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"ds.Tair.isel(time=1).hvplot(\n",
43+
" projection=ccrs.Orthographic(-90, 30),\n",
44+
" coastline=True,\n",
45+
")"
46+
]
47+
}
48+
],
49+
"metadata": {
50+
"kernelspec": {
51+
"display_name": "python3",
52+
"language": "python",
53+
"name": "python3"
54+
},
55+
"language_info": {
56+
"codemirror_mode": {
57+
"name": "ipython",
58+
"version": 3
59+
},
60+
"file_extension": ".py",
61+
"mimetype": "text/x-python",
62+
"name": "python",
63+
"nbconvert_exporter": "python",
64+
"pygments_lexer": "ipython3",
65+
"version": "3.12.3"
66+
}
67+
},
68+
"nbformat": 4,
69+
"nbformat_minor": 2
70+
}

0 commit comments

Comments
 (0)