Skip to content

Commit

Permalink
docs: use html for notebook download links (#1976)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli authored Oct 4, 2023
1 parent 1197094 commit 1eddf86
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
44 changes: 32 additions & 12 deletions .docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@
# -- determine if running on readthedocs ------------------------------------
on_rtd = os.environ.get("READTHEDOCS") == "True"

# -- determine if this version is a release candidate
with open("../README.md") as f:
lines = f.readlines()
rc_text = ""
for line in lines:
if line.startswith("### Version"):
if "release candidate" in line:
rc_text = "release candidate"
break
# -- determine if this is a development or release version ------------------
branch_or_version = __version__ if "dev" not in __version__ else "develop"

# -- get authors
with open("../CITATION.cff") as f:
Expand All @@ -45,8 +38,6 @@
for line in lines:
if line.startswith("**Documentation for version"):
line = f"**Documentation for version {__version__}"
if rc_text != "":
line += f" --- {rc_text}"
line += "**\n"
f.write(line)

Expand Down Expand Up @@ -272,6 +263,35 @@
nbsphinx_prolog = (
r"""
{% set docname = env.doc2path(env.docname, base=None) %}
.. raw:: html
<div class="admonition note">
This page was generated from
<a class="reference external" href="https://github.com/modflowpy/flopy/blob/"""
+ branch_or_version
+ r"""/.docs/Notebooks/{{ env.docname.split('/')|last|e + '.py' }}">{{ env.docname.split('/')|last|e + '.py' }}</a>.
It's also available as a <a href="{{ env.docname.split('/')|last|e + '.ipynb' }}" class="reference download internal" download>notebook</a>.
<script>
if (document.location.host) {
let nbviewer_link = document.createElement('a');
nbviewer_link.setAttribute('href',
'https://nbviewer.org/url' +
(window.location.protocol == 'https:' ? 's/' : '/') +
window.location.host +
window.location.pathname.slice(0, -4) +
'ipynb');
nbviewer_link.innerHTML = 'View in <em>nbviewer</em>';
nbviewer_link.innerHTML = 'Or view it on <em>nbviewer</em>';
nbviewer_link.classList.add('reference');
nbviewer_link.classList.add('external');
document.currentScript.replaceWith(nbviewer_link, '.');
}
</script>
</div>
"""
+ Path("prolog.rst").read_text()
)

# Import Matplotlib to avoid this message in notebooks:
# "Matplotlib is building the font cache; this may take a moment."
import matplotlib.pyplot
10 changes: 0 additions & 10 deletions .docs/prolog.rst

This file was deleted.

0 comments on commit 1eddf86

Please sign in to comment.