Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorials: add Open in Studio badge #2146

Merged
merged 7 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/_static/badge-height.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* https://github.com/pytorch/pytorch_sphinx_theme/issues/140 */
.tutorial-badge {
height: 50px !important;
width: auto !important;
}
4 changes: 0 additions & 4 deletions docs/_static/button-width.css

This file was deleted.

22 changes: 3 additions & 19 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
html_favicon = os.path.join('..', 'logo', 'favicon.ico')

html_static_path = ['_static']
html_css_files = ['button-width.css', 'notebook-prompt.css', 'table-scroll.css']
html_css_files = ['badge-height.css', 'notebook-prompt.css', 'table-scroll.css']

# -- Extension configuration -------------------------------------------------

Expand Down Expand Up @@ -127,24 +127,8 @@

# nbsphinx
nbsphinx_execute = 'never'
# TODO: branch/tag should change depending on which version of docs you look at
# 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
:alt: Open in Colab
:target: {{ host }}/github/{{ repo }}/blob/{{ branch }}/{{ urlpath }}
"""
with open(os.path.join('tutorials', 'prolog.rst.jinja')) as f:
nbsphinx_prolog = f.read()

# Disables requirejs in nbsphinx to enable compatibility with the pytorch_sphinx_theme
# See more information here https://github.com/spatialaudio/nbsphinx/issues/599
Expand Down
31 changes: 31 additions & 0 deletions docs/tutorials/prolog.rst.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{# Macros #}
{% macro image(badge, class, alt, target) %}
.. image:: {{ badge }}
:class: {{ class }}
:alt: {{ alt }}
:target: {{ target }}
{% endmacro %}

{# Global variables #}
{% if "dev" in env.config.release %}
{% set branch = "main" %}
{% else %}
{% set branch = "releases/v" ~ env.config.version %}
{% endif %}
{% set class = "tutorial-badge" %}
{% set path = "/microsoft/torchgeo/blob/" ~ branch ~ "/docs/" ~ env.docname ~ ".ipynb" %}

{# Lightning Studio #}
{% set badge = "https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/studio-badge.svg" %}
{% set alt = "Open in Studio" %}
{% set repo_url = "https://github.com" ~ path %}
{% set target = "https://lightning.ai/new?repo_url=" ~ repo_url | urlencode %}

{{ image(badge, class, alt, target) }}

{# Google Colab #}
{% set badge = "https://colab.research.google.com/assets/colab-badge.svg" %}
{% set alt = "Open in Colab" %}
{% set target = "https://colab.research.google.com/github" ~ path %}

{{ image(badge, class, alt, target) }}
Loading