Skip to content

Commit 56874cb

Browse files
matthew-brettpre-commit-ci[bot]choldgraf
authored
Jupyterlite button - patched, merged version of #655 (#914)
* Jupyterlite button * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add some documentation for JupyterLite * Update docs/content/launch.md --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Chris Holdgraf <[email protected]>
1 parent 23f6936 commit 56874cb

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

docs/content/launch.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# Launch buttons for interactivity
33

44
You can automatically add buttons that allow users to interact with your
5-
book's content. This is either by directing them to a BinderHub or JupyterHub
6-
that runs in the cloud, or by making your page interactive using Thebe.
5+
book's content. This is can be by directing them to
6+
a [JupyterLite](https://jupyterlite.readthedocs.io) installation (that runs in
7+
the user's browser) or one of BinderHub or JupyterHub (that runs in the
8+
cloud), or by making your page interactive using Thebe.
79

8-
To use either Binder or JupyterHub links, you'll first need to configure your
9-
documentation's repository url:
10+
To use any of JupyterLite or Binder or JupyterHub links, you'll first need to
11+
configure your documentation's repository url:
1012

1113
```python
1214
html_theme_options = {
@@ -26,6 +28,28 @@ folder as your content, then Binder/JupyterHub links will point to the ipynb
2628
file instead of the text file.
2729
```
2830

31+
## JupyterLite
32+
33+
If you are adding [JupyterLite](https://github.com/jupyterlite/jupyterlite) links to your page, first work out where your
34+
JupyterLite instance will be serving from, then add the URL to your
35+
configuration. In the example below, we've set up JupyterLite pages at the
36+
base URL of the main pages site, and at subdirectory `interact/lab`:
37+
38+
```python
39+
html_theme_options = {
40+
...
41+
"launch_buttons": {
42+
"jupyterlite_url": "interact/lab/index.html"
43+
},
44+
...
45+
}
46+
```
47+
48+
See <https://odsti.github.io/cfd-textbook> for an example
49+
[JupyterBook](https://jupyterbook.org) project serving JupyterLite using this
50+
configuration, and <https://github.com/odsti/cfd-textbook> for the driving
51+
repository.
52+
2953
## Binder / BinderHub
3054

3155
To add Binder links to your page, add the following configuration:

src/sphinx_book_theme/header_buttons/launch.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ def add_launch_buttons(
4949
or not _is_notebook(app, context)
5050
or not any(
5151
launch_buttons.get(key)
52-
for key in ("binderhub_url", "jupyterhub_url", "thebe", "colab_url")
52+
for key in (
53+
"binderhub_url",
54+
"jupyterhub_url",
55+
"thebe",
56+
"colab_url",
57+
"jupyterlite_url",
58+
)
5359
)
5460
):
5561
return
@@ -114,6 +120,9 @@ def add_launch_buttons(
114120
binderhub_url = launch_buttons.get("binderhub_url", "").strip("/")
115121
colab_url = launch_buttons.get("colab_url", "").strip("/")
116122
deepnote_url = launch_buttons.get("deepnote_url", "").strip("/")
123+
# jupyterlite_url could be absolute but without a domain, so we only
124+
# strip trailing slashes, not leading ones
125+
jupyterlite_url = launch_buttons.get("jupyterlite_url", "").rstrip("/")
117126

118127
# Loop through each provider and add a button for it if needed
119128
if binderhub_url:
@@ -187,6 +196,20 @@ def add_launch_buttons(
187196
}
188197
)
189198

199+
if jupyterlite_url:
200+
jl_ext = launch_buttons.get("jupyterlite_ext", extension).strip()
201+
jl_rel_repo = f"{book_relpath}{pagename}{jl_ext}"
202+
url = f"{jupyterlite_url}?path={jl_rel_repo}"
203+
launch_buttons_list.append(
204+
{
205+
"type": "link",
206+
"text": "JupyterLite",
207+
"tooltip": "Launch via JupyterLite",
208+
"icon": "_static/images/logo_jupyterlite.svg",
209+
"url": url,
210+
}
211+
)
212+
190213
# Add thebe flag in context
191214
if launch_buttons.get("thebe", False):
192215
launch_buttons_list.append(
Lines changed: 17 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)