Skip to content

Commit

Permalink
Correctly specify the source path to a logo to copy_asset_file (#1746)
Browse files Browse the repository at this point in the history
I think this fixes #1385, I think that bug report is expecting to be able to pass a logo in the docs/_static directory but according to the docs here: https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/branding.html#different-logos-for-light-and-dark-mode the path should be relative to conf.py.

I think the actual bug is that we were not passing the correct source to the sphinx copy function which exits silently (for some reason) if the source does not exist.
  • Loading branch information
Cadair authored May 27, 2024
1 parent aabe57d commit 541950a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/pydata_sphinx_theme/logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def copy_logo_images(app: Sphinx, exception=None) -> None:
warning = partial(maybe_warn, app)
logo = get_theme_options_dict(app).get("logo", {})
staticdir = Path(app.builder.outdir) / "_static"
assert staticdir.is_absolute()
for kind in ["light", "dark"]:
path_image = logo.get(f"image_{kind}")
if not path_image or isurl(path_image):
Expand All @@ -71,12 +72,14 @@ def copy_logo_images(app: Sphinx, exception=None) -> None:
# file already exists in static dir e.g. because a theme has
# bundled the logo and installed it there
continue
if not (Path(app.srcdir) / path_image).exists():
full_logo_path = Path(app.srcdir) / path_image
assert full_logo_path.is_absolute()
if not full_logo_path.exists():
warning(f"Path to {kind} image logo does not exist: {path_image}")
# Ensure templates cannot be passed for logo path to avoid security vulnerability
if path_image.lower().endswith("_t"):
raise ExtensionError(
f"The {kind} logo path '{path_image}' looks like a Sphinx template; "
"please provide a static logo image."
)
copy_asset_file(path_image, staticdir)
copy_asset_file(str(full_logo_path), staticdir)

0 comments on commit 541950a

Please sign in to comment.