Skip to content

Commit

Permalink
Make implicit thumbnails lower priority than explicit
Browse files Browse the repository at this point in the history
The previous resolution order was to use a thumbnail specified in a
notebook, then the one in the conf.py, if present. If a default
implicit thumbnail is used, it should be lower priority than these two
options.
  • Loading branch information
angus-g authored and mgeier committed Mar 12, 2023
1 parent 9d5a178 commit 21b9063
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion doc/configuration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@
"(i.e. source file without suffix but with subdirectories)\n",
"-- optionally containing wildcards --\n",
"to a thumbnail path to be used in a\n",
"[thumbnail gallery](subdir/gallery.ipynb).\n",
"[thumbnail gallery](subdir/gallery.ipynb). Thumbnails specified\n",
"in notebooks will override those provided in this dictionary.\n",
"\n",
"See [Specifying Thumbnails](gallery/thumbnail-from-conf-py.ipynb)."
]
Expand Down
13 changes: 12 additions & 1 deletion src/nbsphinx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ def warning(msg, *args):

if thumbnail_cell:
thumbnail['filename'] = thumbnail_filename
thumbnail['implicit'] = False
if tooltip:
thumbnail['tooltip'] = tooltip

Expand All @@ -505,6 +506,7 @@ def warning(msg, *args):
# default to the last figure in the notebook, if it's a valid thumbnail
if thumbnail_filename:
thumbnail['filename'] = thumbnail_filename
thumbnail['implicit'] = True

resources['nbsphinx_thumbnail'] = thumbnail
return rststr, resources
Expand Down Expand Up @@ -1735,15 +1737,24 @@ def has_wildcard(pattern):
thumbnail = app.env.nbsphinx_thumbnails.get(doc, {})
tooltip = thumbnail.get('tooltip', '')
filename = thumbnail.get('filename', '')
was_implicit_thumbnail = thumbnail.get('implicit', True)

# thumbnail priority: broken, explicit in notebook, from conf.py
# implicit in notebook, default
if filename is _BROKEN_THUMBNAIL:
filename = os.path.join(
base, '_static', 'nbsphinx-broken-thumbnail.svg')
elif filename:
elif filename and not was_implicit_thumbnail:
# thumbnail from tagged cell or metadata
filename = os.path.join(
base, app.builder.imagedir, filename)
elif conf_py_thumbnail:
# NB: Settings from conf.py can be overwritten in notebook
filename = os.path.join(base, conf_py_thumbnail)
elif filename:
# implicit thumbnail from an image in the notebook
filename = os.path.join(
base, app.builder.imagedir, filename)
else:
filename = os.path.join(
base, '_static', 'nbsphinx-no-thumbnail.svg')
Expand Down

0 comments on commit 21b9063

Please sign in to comment.