From 7b5cedd22e61d2eabcbe328ec5caa5515d424601 Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Sun, 26 Jan 2025 23:51:43 -0500 Subject: [PATCH 1/8] BUG: do not add icon links if theme_options[icon_links] is None --- src/pydata_sphinx_theme/__init__.py | 36 +++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/pydata_sphinx_theme/__init__.py b/src/pydata_sphinx_theme/__init__.py index 92944f4c4..07295df4c 100644 --- a/src/pydata_sphinx_theme/__init__.py +++ b/src/pydata_sphinx_theme/__init__.py @@ -40,11 +40,12 @@ def update_config(app): ) # Validate icon links - if not isinstance(theme_options.get("icon_links", []), list): - raise ExtensionError( - "`icon_links` must be a list of dictionaries, you provided " - f"type {type(theme_options.get('icon_links'))}." - ) + if theme_options.get("icon_links") is not None: + if not isinstance(theme_options.get("icon_links", []), list): + raise ExtensionError( + "`icon_links` must be a list of dictionaries, you provided " + f"type {type(theme_options.get('icon_links'))}." + ) # Set the anchor link default to be # if the user hasn't provided their own if not utils.config_provided_by_user(app, "html_permalinks_icon"): @@ -140,18 +141,19 @@ def update_config(app): # Add extra icon links entries if there were shortcuts present # TODO: Deprecate this at some point in the future? icon_links = theme_options.get("icon_links", []) - for url, icon, name in shortcuts: - if theme_options.get(url): - # This defaults to an empty list so we can always insert - icon_links.insert( - 0, - { - "url": theme_options.get(url), - "icon": icon, - "name": name, - "type": "fontawesome", - }, - ) + if icon_links is not None: + for url, icon, name in shortcuts: + if theme_options.get(url): + # This defaults to an empty list so we can always insert + icon_links.insert( + 0, + { + "url": theme_options.get(url), + "icon": icon, + "name": name, + "type": "fontawesome", + }, + ) theme_options["icon_links"] = icon_links # Prepare the logo config dictionary From 2477db017eb9bf9c30dc7b6224c0c723bd80a718 Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Sun, 26 Jan 2025 23:52:59 -0500 Subject: [PATCH 2/8] BUG: do not shorten links if theme_options['shorten_urls'] is not True --- src/pydata_sphinx_theme/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pydata_sphinx_theme/__init__.py b/src/pydata_sphinx_theme/__init__.py index 07295df4c..ed8ccc0ff 100644 --- a/src/pydata_sphinx_theme/__init__.py +++ b/src/pydata_sphinx_theme/__init__.py @@ -284,7 +284,10 @@ def setup(app: Sphinx) -> Dict[str, str]: app.add_html_theme("pydata_sphinx_theme", str(theme_path)) - app.add_post_transform(short_link.ShortenLinkTransform) + + theme_options = utils.get_theme_options_dict(app) + if theme_options.get("shorten_urls") is True: + app.add_post_transform(short_link.ShortenLinkTransform) app.connect("builder-inited", translator.setup_translators) app.connect("builder-inited", update_config) From 91c3609719239a07281b76dcc12b4a03582dd288 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 04:56:23 +0000 Subject: [PATCH 3/8] [pre-commit.ci] Automatic linting and formatting fixes --- src/pydata_sphinx_theme/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pydata_sphinx_theme/__init__.py b/src/pydata_sphinx_theme/__init__.py index ed8ccc0ff..ce53bef2d 100644 --- a/src/pydata_sphinx_theme/__init__.py +++ b/src/pydata_sphinx_theme/__init__.py @@ -284,7 +284,6 @@ def setup(app: Sphinx) -> Dict[str, str]: app.add_html_theme("pydata_sphinx_theme", str(theme_path)) - theme_options = utils.get_theme_options_dict(app) if theme_options.get("shorten_urls") is True: app.add_post_transform(short_link.ShortenLinkTransform) From 694719558ceda6d20d457a384159015d08e0af94 Mon Sep 17 00:00:00 2001 From: gabalafou Date: Tue, 17 Jun 2025 20:43:16 +0200 Subject: [PATCH 4/8] Revert "BUG: do not add icon links if theme_options[icon_links] is None" This reverts commit 7b5cedd22e61d2eabcbe328ec5caa5515d424601. --- src/pydata_sphinx_theme/__init__.py | 36 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/pydata_sphinx_theme/__init__.py b/src/pydata_sphinx_theme/__init__.py index ce53bef2d..b5d78ee07 100644 --- a/src/pydata_sphinx_theme/__init__.py +++ b/src/pydata_sphinx_theme/__init__.py @@ -40,12 +40,11 @@ def update_config(app): ) # Validate icon links - if theme_options.get("icon_links") is not None: - if not isinstance(theme_options.get("icon_links", []), list): - raise ExtensionError( - "`icon_links` must be a list of dictionaries, you provided " - f"type {type(theme_options.get('icon_links'))}." - ) + if not isinstance(theme_options.get("icon_links", []), list): + raise ExtensionError( + "`icon_links` must be a list of dictionaries, you provided " + f"type {type(theme_options.get('icon_links'))}." + ) # Set the anchor link default to be # if the user hasn't provided their own if not utils.config_provided_by_user(app, "html_permalinks_icon"): @@ -141,19 +140,18 @@ def update_config(app): # Add extra icon links entries if there were shortcuts present # TODO: Deprecate this at some point in the future? icon_links = theme_options.get("icon_links", []) - if icon_links is not None: - for url, icon, name in shortcuts: - if theme_options.get(url): - # This defaults to an empty list so we can always insert - icon_links.insert( - 0, - { - "url": theme_options.get(url), - "icon": icon, - "name": name, - "type": "fontawesome", - }, - ) + for url, icon, name in shortcuts: + if theme_options.get(url): + # This defaults to an empty list so we can always insert + icon_links.insert( + 0, + { + "url": theme_options.get(url), + "icon": icon, + "name": name, + "type": "fontawesome", + }, + ) theme_options["icon_links"] = icon_links # Prepare the logo config dictionary From c6e83ee5e41a407bba2dc61c3bfa52866ed72ef3 Mon Sep 17 00:00:00 2001 From: gabalafou Date: Tue, 17 Jun 2025 20:49:04 +0200 Subject: [PATCH 5/8] respond to review by @drammock --- src/pydata_sphinx_theme/__init__.py | 2 ++ src/pydata_sphinx_theme/theme/pydata_sphinx_theme/theme.conf | 1 + 2 files changed, 3 insertions(+) diff --git a/src/pydata_sphinx_theme/__init__.py b/src/pydata_sphinx_theme/__init__.py index b5d78ee07..db7b80fa0 100644 --- a/src/pydata_sphinx_theme/__init__.py +++ b/src/pydata_sphinx_theme/__init__.py @@ -44,6 +44,8 @@ def update_config(app): raise ExtensionError( "`icon_links` must be a list of dictionaries, you provided " f"type {type(theme_options.get('icon_links'))}." + "If you wish to disable this feature, either do not provide " + "a value (leave undefined), or set to an empty list." ) # Set the anchor link default to be # if the user hasn't provided their own diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/theme.conf b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/theme.conf index 111691ea2..3ea564058 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/theme.conf +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/theme.conf @@ -37,6 +37,7 @@ logo_link = surface_warnings = True back_to_top_button = True search_as_you_type = False +shorten_urls = True # Template placement in theme layouts navbar_start = navbar-logo From f4a03dd3eebcd73de0d416624df64c8401bf1789 Mon Sep 17 00:00:00 2001 From: gabalafou Date: Thu, 19 Jun 2025 02:16:24 -0500 Subject: [PATCH 6/8] Update src/pydata_sphinx_theme/__init__.py Co-authored-by: Daniel McCloy --- src/pydata_sphinx_theme/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pydata_sphinx_theme/__init__.py b/src/pydata_sphinx_theme/__init__.py index db7b80fa0..d492dae44 100644 --- a/src/pydata_sphinx_theme/__init__.py +++ b/src/pydata_sphinx_theme/__init__.py @@ -285,7 +285,7 @@ def setup(app: Sphinx) -> Dict[str, str]: app.add_html_theme("pydata_sphinx_theme", str(theme_path)) theme_options = utils.get_theme_options_dict(app) - if theme_options.get("shorten_urls") is True: + if theme_options.get("shorten_urls"): app.add_post_transform(short_link.ShortenLinkTransform) app.connect("builder-inited", translator.setup_translators) From 97d93c4c624d67c5ad0f2b09464812c679b62b0f Mon Sep 17 00:00:00 2001 From: gabalafou Date: Fri, 4 Jul 2025 17:11:08 +0200 Subject: [PATCH 7/8] test for shorten_urls=False in configuration --- tests/test_build.py | 18 +++++++++ .../github_links_not_shortened.html | 19 +++++++++ .../gitlab_links_not_shortened.html | 40 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 tests/test_build/github_links_not_shortened.html create mode 100644 tests/test_build/gitlab_links_not_shortened.html diff --git a/tests/test_build.py b/tests/test_build.py index 8444da330..93129616c 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -853,6 +853,24 @@ def test_shorten_link(sphinx_build_factory, file_regression) -> None: file_regression.check(gitlab.prettify(), basename="gitlab_links", extension=".html") +def test_dont_shorten_link(sphinx_build_factory, file_regression) -> None: + """Regression test for setting shorten_urls to false .""" + confoverrides = { + "html_theme_options": {"shorten_urls": False}, + } + sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build() + + github = sphinx_build.html_tree("page1.html").select(".github-container")[0] + file_regression.check( + github.prettify(), basename="github_links_not_shortened", extension=".html" + ) + + gitlab = sphinx_build.html_tree("page1.html").select(".gitlab-container")[0] + file_regression.check( + gitlab.prettify(), basename="gitlab_links_not_shortened", extension=".html" + ) + + def test_math_header_item(sphinx_build_factory, file_regression) -> None: """Regression test for math items in a header title.""" sphinx_build = sphinx_build_factory("base").build() diff --git a/tests/test_build/github_links_not_shortened.html b/tests/test_build/github_links_not_shortened.html new file mode 100644 index 000000000..f0e0e93ac --- /dev/null +++ b/tests/test_build/github_links_not_shortened.html @@ -0,0 +1,19 @@ + diff --git a/tests/test_build/gitlab_links_not_shortened.html b/tests/test_build/gitlab_links_not_shortened.html new file mode 100644 index 000000000..0921317a4 --- /dev/null +++ b/tests/test_build/gitlab_links_not_shortened.html @@ -0,0 +1,40 @@ + From e97e91ae27f6cda322cdb61245979c1bc9993a00 Mon Sep 17 00:00:00 2001 From: gabalafou Date: Mon, 7 Jul 2025 14:36:52 +0200 Subject: [PATCH 8/8] fix tests --- tests/test_build.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_build.py b/tests/test_build.py index 452a37e6c..b60027642 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -844,7 +844,10 @@ def test_theme_switcher(sphinx_build_factory, file_regression) -> None: def test_shorten_link(sphinx_build_factory, file_regression) -> None: """Regression test for "edit on " link shortening.""" - sphinx_build = sphinx_build_factory("base").build() + confoverrides = { + "html_theme_options": {"shorten_urls": True}, + } + sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build() github = sphinx_build.html_tree("page1.html").select(".github-container")[0] file_regression.check(github.prettify(), basename="github_links", extension=".html")