Skip to content

Commit 9d5b421

Browse files
committed
creating nbsphinx prologue with links to binder and github on tutorial pages
1 parent 1da16bb commit 9d5b421

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docs/conf.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
"github_user": "OceanParcels",
216216
"github_repo": "parcels",
217217
"github_version": "main",
218-
"doc_path": "docs",
218+
"doc_path": "docs"
219219
}
220220

221221

@@ -384,6 +384,26 @@ def linkcode_resolve(domain, info):
384384
nbsphinx_execute = "never"
385385
# -- Options for LaTeX output ---------------------------------------------
386386

387+
# -- Detect branch name -----------------------------------
388+
# Works on GitHub Actions, ReadTheDocs, and local fallback
389+
BRANCH = (
390+
os.environ.get("GITHUB_REF_NAME") # GitHub Actions
391+
or os.environ.get("READTHEDOCS_VERSION") # ReadTheDocs
392+
or "main" # fallback
393+
)
394+
395+
nbsphinx_prolog = f"""
396+
.. raw:: html
397+
398+
<a href="https://mybinder.org/v2/gh/OceanParcels/Parcels/{BRANCH}?urlpath=lab/tree/docs/{{{{ env.doc2path(env.docname, base=None) }}}}" target="_blank">
399+
<img alt="Binder badge" src="https://mybinder.org/badge_logo.svg">
400+
</a>
401+
or view it
402+
<a href="https://github.com/OceanParcels/Parcels/blob/{BRANCH}/docs/{{{{ env.doc2path(env.docname, base=None) }}}}" target="_blank">
403+
on GitHub
404+
</a>
405+
"""
406+
387407
latex_elements = {
388408
# The paper size ('letterpaper' or 'a4paper').
389409
# 'papersize': 'letterpaper',

0 commit comments

Comments
 (0)