Skip to content

Commit

Permalink
Tutorials: add Open in Studio badge
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjstewart committed Jul 1, 2024
1 parent e84b50c commit 46ad239
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/_static/button-width.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.colabbadge {
.badge {
height: 50px !important;
width: auto !important;
}
25 changes: 19 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,32 @@
# TODO: width option of image directive is broken, see:
# https://github.com/pytorch/pytorch_sphinx_theme/issues/140
nbsphinx_prolog = """
{% set host = "https://colab.research.google.com" %}
{% set repo = "microsoft/torchgeo" %}
{% set urlpath = "docs/" ~ env.docname ~ ".ipynb" %}
{% if "dev" in env.config.release %}
{% set branch = "main" %}
{% else %}
{% set branch = "releases/v" ~ env.config.version %}
{% endif %}
.. image:: {{ host }}/assets/colab-badge.svg
:class: colabbadge
{% set host = "https://colab.research.google.com" %}
{% set badge = host ~ "/assets/colab-badge.svg" %}
{% set repo = "microsoft/torchgeo" %}
{% set path = "docs/" ~ env.docname ~ ".ipynb" %}
.. image:: {{ badge }}
:class: badge
:alt: Open in Colab
:target: {{ host }}/github/{{ repo }}/blob/{{ branch }}/{{ urlpath }}
:target: {{ host }}/github/{{ repo }}/blob/{{ branch }}/{{ path }}
{% set host = "https://lightning.ai/new" %}
{% set badge = "https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com" %}
{% set badge = badge ~ "/app-2/studio-badge.svg" %}
{% set repo_url = "https://github.com/" ~ repo ~ "/blob/" ~ branch ~ "/" ~ path %}
{% set repo_url = repo_url | replace(":", "%3A") | replace("/", "%2F") %}
.. image:: {{ badge }}
:class: badge
:alt: Open in Studio
:target: {{ host }}?repo_url={{ repo_url }}
"""

# Disables requirejs in nbsphinx to enable compatibility with the pytorch_sphinx_theme
Expand Down

0 comments on commit 46ad239

Please sign in to comment.