From 21a83a6d46b2703336786d48b93fa5681ce12a20 Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Thu, 17 Oct 2024 16:26:52 +0100 Subject: [PATCH 1/4] Jupyterlite button --- .../header_buttons/launch.py | 20 ++++++++++++++++++- .../static/images/logo_jupyterlite.svg | 17 ++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/sphinx_book_theme/theme/sphinx_book_theme/static/images/logo_jupyterlite.svg diff --git a/src/sphinx_book_theme/header_buttons/launch.py b/src/sphinx_book_theme/header_buttons/launch.py index 20f93b4c2..5ea09f1a5 100644 --- a/src/sphinx_book_theme/header_buttons/launch.py +++ b/src/sphinx_book_theme/header_buttons/launch.py @@ -49,7 +49,8 @@ def add_launch_buttons( or not _is_notebook(app, context) or not any( launch_buttons.get(key) - for key in ("binderhub_url", "jupyterhub_url", "thebe", "colab_url") + for key in ("binderhub_url", "jupyterhub_url", "thebe", + "colab_url", "jupyterlite_url") ) ): return @@ -114,6 +115,9 @@ def add_launch_buttons( binderhub_url = launch_buttons.get("binderhub_url", "").strip("/") colab_url = launch_buttons.get("colab_url", "").strip("/") deepnote_url = launch_buttons.get("deepnote_url", "").strip("/") + # jupyterlite_url could be absolute but without a domain, so we only + # strip trailing slashes, not leading ones + jupyterlite_url = launch_buttons.get("jupyterlite_url", "").rstrip("/") # Loop through each provider and add a button for it if needed if binderhub_url: @@ -187,6 +191,20 @@ def add_launch_buttons( } ) + if jupyterlite_url: + jl_ext = launch_buttons.get("jupyterlite_ext", extension).strip() + jl_rel_repo = f"{book_relpath}{pagename}{jl_ext}" + url = f"{jupyterlite_url}?path={jl_rel_repo}" + launch_buttons_list.append( + { + "type": "link", + "text": "JupyterLite", + "tooltip": "Launch via JupyterLite", + "icon": "_static/images/logo_jupyterlite.svg", + "url": url, + } + ) + # Add thebe flag in context if launch_buttons.get("thebe", False): launch_buttons_list.append( diff --git a/src/sphinx_book_theme/theme/sphinx_book_theme/static/images/logo_jupyterlite.svg b/src/sphinx_book_theme/theme/sphinx_book_theme/static/images/logo_jupyterlite.svg new file mode 100644 index 000000000..09e821f66 --- /dev/null +++ b/src/sphinx_book_theme/theme/sphinx_book_theme/static/images/logo_jupyterlite.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + From 8a1f7b79bcc385ffdbaae5d5d6bf3a85aa831499 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:24:12 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/sphinx_book_theme/header_buttons/launch.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sphinx_book_theme/header_buttons/launch.py b/src/sphinx_book_theme/header_buttons/launch.py index 5ea09f1a5..5ef0f0f1b 100644 --- a/src/sphinx_book_theme/header_buttons/launch.py +++ b/src/sphinx_book_theme/header_buttons/launch.py @@ -49,8 +49,13 @@ def add_launch_buttons( or not _is_notebook(app, context) or not any( launch_buttons.get(key) - for key in ("binderhub_url", "jupyterhub_url", "thebe", - "colab_url", "jupyterlite_url") + for key in ( + "binderhub_url", + "jupyterhub_url", + "thebe", + "colab_url", + "jupyterlite_url", + ) ) ): return From beeb520c6eaf7f92b5c83f4f5b030dd07ad3fe44 Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Thu, 5 Jun 2025 18:01:56 +0100 Subject: [PATCH 3/4] Add some documentation for JupyterLite --- docs/content/launch.md | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/content/launch.md b/docs/content/launch.md index 8c851c344..bca8b4467 100644 --- a/docs/content/launch.md +++ b/docs/content/launch.md @@ -2,11 +2,13 @@ # Launch buttons for interactivity You can automatically add buttons that allow users to interact with your -book's content. This is either by directing them to a BinderHub or JupyterHub -that runs in the cloud, or by making your page interactive using Thebe. +book's content. This is can be by directing them to +a [JupyterLite](https://jupyterlite.readthedocs.io) installation (that runs in +the user's browser) or one of BinderHub or JupyterHub (that runs in the +cloud), or by making your page interactive using Thebe. -To use either Binder or JupyterHub links, you'll first need to configure your -documentation's repository url: +To use any of JupyterLite or Binder or JupyterHub links, you'll first need to +configure your documentation's repository url: ```python html_theme_options = { @@ -26,6 +28,28 @@ folder as your content, then Binder/JupyterHub links will point to the ipynb file instead of the text file. ``` +## JupyterLite + +If you are adding JupyterLite links to your page, first work out where your +JupyterLite instance will be serving from, then add the URL to your +configuration. In the example below, we've set up JupyterLite pages at the +base URL of the main pages site, and at subdirectory `interact/lab`: + +```python +html_theme_options = { + ... + "launch_buttons": { + "jupyterlite_url": "interact/lab/index.html" + }, + ... +} +``` + +See for an example +[JupyterBook](https://jupyterbook.org) project serving JupyterLite using this +configuration, and for the driving +repository. + ## Binder / BinderHub To add Binder links to your page, add the following configuration: From 137ac040dbed7f11bba14f46f0a510cc603f7354 Mon Sep 17 00:00:00 2001 From: Chris Holdgraf Date: Thu, 5 Jun 2025 10:16:04 -0700 Subject: [PATCH 4/4] Update docs/content/launch.md --- docs/content/launch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/launch.md b/docs/content/launch.md index bca8b4467..7090243c7 100644 --- a/docs/content/launch.md +++ b/docs/content/launch.md @@ -30,7 +30,7 @@ file instead of the text file. ## JupyterLite -If you are adding JupyterLite links to your page, first work out where your +If you are adding [JupyterLite](https://github.com/jupyterlite/jupyterlite) links to your page, first work out where your JupyterLite instance will be serving from, then add the URL to your configuration. In the example below, we've set up JupyterLite pages at the base URL of the main pages site, and at subdirectory `interact/lab`: