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 committed Jan 30, 2023
1 parent 5ae7107 commit f8b7d3a
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 @@ -388,7 +388,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.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ def warning(msg, *args):

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

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

resources['nbsphinx_thumbnail'] = thumbnail
return rststr, resources
Expand Down Expand Up @@ -2249,15 +2251,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', 'broken_example.png')
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', 'no_image.png')
entries.append((title, uri, filename, tooltip))
Expand Down

0 comments on commit f8b7d3a

Please sign in to comment.