From 9663810730d157cc14770207ee7b4e00b2db2790 Mon Sep 17 00:00:00 2001 From: Nils Lehmann Date: Thu, 1 Aug 2024 21:48:06 +0200 Subject: [PATCH 1/6] lightning launch button --- docs/conf.py | 1 + docs/content/launch.md | 16 ++++++++++++++++ src/sphinx_book_theme/header_buttons/launch.py | 17 +++++++++++++++++ .../static/images/logo_lightning_studio.svg | 3 +++ tests/sites/base/conf.py | 1 + tests/test_build/build__header-article.html | 10 ++++++++++ tests/test_build/test_header_launchbtns.html | 10 ++++++++++ 7 files changed, 58 insertions(+) create mode 100644 src/sphinx_book_theme/theme/sphinx_book_theme/static/images/logo_lightning_studio.svg diff --git a/docs/conf.py b/docs/conf.py index 7eafdb884..561da0917 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -113,6 +113,7 @@ "binderhub_url": "https://mybinder.org", "colab_url": "https://colab.research.google.com/", "deepnote_url": "https://deepnote.com/", + "lightning_studio_url": "https://lightning.ai/", "notebook_interface": "jupyterlab", "thebe": True, # "jupyterhub_url": "https://datahub.berkeley.edu", # For testing diff --git a/docs/content/launch.md b/docs/content/launch.md index 8c851c344..a83d5e5d4 100644 --- a/docs/content/launch.md +++ b/docs/content/launch.md @@ -85,6 +85,22 @@ html_theme_options = { This will create a new Deepnote project every time you click the launch button. ``` +## Lightning Studio + +To add [Ligthning Studio](https://lightning.ai) links to your page, add the following configuration: + + +```python +html_theme_options = { + ... + "launch_buttons": { + "lightning_studio_url": "https://lightning.ai" + }, + ... +} +``` + + ## Live code cells with Thebe diff --git a/src/sphinx_book_theme/header_buttons/launch.py b/src/sphinx_book_theme/header_buttons/launch.py index c00f92937..08ef14cba 100644 --- a/src/sphinx_book_theme/header_buttons/launch.py +++ b/src/sphinx_book_theme/header_buttons/launch.py @@ -116,6 +116,7 @@ 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("/") + lightning_studio_url = launch_buttons.get("lightning_studio_url", "").strip("/") # Loop through each provider and add a button for it if needed if binderhub_url: @@ -189,6 +190,22 @@ def add_launch_buttons( } ) + if lightning_studio_url: + if provider.lower() != "github": + SPHINX_LOGGER.warning(f"Provider {provider} not supported on Lightning.") + else: + github_path = f"%2F{org}%2F{repo}%2Fblob%2F{branch}%2F{path_rel_repo}" + url = f"{lightning_studio_url}/new?repo_url=https://github.com{github_path}" + launch_buttons_list.append( + { + "type": "link", + "text": "Lightning Studio", + "tooltip": translation("Launch on") + " Lightning Studio", + "icon": "_static/images/logo_lightning_studio.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_lightning_studio.svg b/src/sphinx_book_theme/theme/sphinx_book_theme/static/images/logo_lightning_studio.svg new file mode 100644 index 000000000..481762a96 --- /dev/null +++ b/src/sphinx_book_theme/theme/sphinx_book_theme/static/images/logo_lightning_studio.svg @@ -0,0 +1,3 @@ + + + diff --git a/tests/sites/base/conf.py b/tests/sites/base/conf.py index 63f37fe83..0bcf1ec88 100644 --- a/tests/sites/base/conf.py +++ b/tests/sites/base/conf.py @@ -27,6 +27,7 @@ "jupyterhub_url": "https://datahub.berkeley.edu", "colab_url": "https://colab.research.google.com", "deepnote_url": "https://deepnote.com", + "lightning_studio_url": "https://lightning.ai/", "notebook_interface": "jupyterlab", "thebe": True, }, diff --git a/tests/test_build/build__header-article.html b/tests/test_build/build__header-article.html index 4ffce98c7..956bd04c0 100644 --- a/tests/test_build/build__header-article.html +++ b/tests/test_build/build__header-article.html @@ -57,6 +57,16 @@ +
  • + + + Lighting Studio logo + + + Lightning Studio + + +
  • +
  • + + + Lightning Studio logo + + + Lightning Studio + + +
  • - + Lighting Studio logo From c1c16965f8ebec9a84877a5b63f0effcd50b0460 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Fri, 22 Nov 2024 09:39:04 +0000 Subject: [PATCH 6/6] Update tests/test_build/test_header_launchbtns.html Co-authored-by: Adam J. Stewart --- tests/test_build/test_header_launchbtns.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_build/test_header_launchbtns.html b/tests/test_build/test_header_launchbtns.html index d86b9b326..4a29f4f32 100644 --- a/tests/test_build/test_header_launchbtns.html +++ b/tests/test_build/test_header_launchbtns.html @@ -45,7 +45,7 @@
  • - + Lightning Studio logo