From 4d9097039e192a2027bac33f0795eafb8ca91420 Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Fri, 3 Mar 2023 00:12:48 +0100 Subject: [PATCH] fix: don't use relative path to _static output folder (#46) * fix: don't use relative path to _static output folder * fix: use only the name of the file * fix: don't edit the favicon in _static_to_href * fix don't use pathto * set back pathto --- sphinx_favicon/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sphinx_favicon/__init__.py b/sphinx_favicon/__init__.py index d45ca7c..4ece996 100644 --- a/sphinx_favicon/__init__.py +++ b/sphinx_favicon/__init__.py @@ -147,7 +147,7 @@ def _sizes( return favicon -def _static_to_href(pathto: Callable, favicon: Dict[str, str]) -> Dict[str, str]: +def _static_to_href(pathto: Callable, init_favicon: Dict[str, str]) -> Dict[str, str]: """Replace static ref to fully qualified href. if the ``href`` is a relative path then it's replaced with the correct ``href``. We keep checking for ``static-file`` for legacy reasons. @@ -156,11 +156,14 @@ def _static_to_href(pathto: Callable, favicon: Dict[str, str]) -> Dict[str, str] Args: pathto: Sphinx helper_ function to handle relative URLs - favicon: The favicon description as set in the conf.py file + init_favicon: The favicon description as set in the conf.py file Returns: The favicon with a fully qualified href """ + # work on a copy of the favicon (mutable issue) + favicon = init_favicon.copy() + # exit if the favicon tag has no href (like meta) if not (FILE_FIELD in favicon or "href" in favicon): return favicon @@ -175,8 +178,7 @@ def _static_to_href(pathto: Callable, favicon: Dict[str, str]) -> Dict[str, str] # if the link is absolute do nothing, else replace it with a full one if not is_absolute: - path = f"{OUTPUT_STATIC_DIR}/{link}" - favicon["href"] = pathto(path, resource=True) + favicon["href"] = pathto(f"{OUTPUT_STATIC_DIR}/{link}", resource=True) return favicon