diff --git a/src/pydata_sphinx_theme/__init__.py b/src/pydata_sphinx_theme/__init__.py index 0b1ed7d4fe..2178b6d815 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 @@ -282,7 +284,9 @@ 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"): + app.add_post_transform(short_link.ShortenLinkTransform) app.connect("builder-inited", translator.setup_translators) app.connect("builder-inited", update_config) 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 30d18cc4ae..96d71bb70b 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 diff --git a/tests/test_build.py b/tests/test_build.py index f40a38acd2..b600276421 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") @@ -853,6 +856,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 0000000000..f0e0e93ac8 --- /dev/null +++ b/tests/test_build/github_links_not_shortened.html @@ -0,0 +1,19 @@ +
+

+ + https://github.com + + + https://github.com/pydata + + + https://github.com/pydata/pydata-sphinx-theme + + + https://github.com/pydata/pydata-sphinx-theme/pull/1012 + + + https://github.com/orgs/pydata/projects/2 + +

+
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 0000000000..0921317a4c --- /dev/null +++ b/tests/test_build/gitlab_links_not_shortened.html @@ -0,0 +1,40 @@ +
+

+ + https://gitlab.com + + + https://gitlab.com/gitlab-org + + + https://gitlab.com/gitlab-org/gitlab + + + https://gitlab.com/gitlab-org/gitlab/-/issues/375583 + + + https://gitlab.com/gitlab-org/gitlab/issues/375583 + + + https://gitlab.com/gitlab-org/gitlab/-/issues/ + + + https://gitlab.com/gitlab-org/gitlab/issues/ + + + https://gitlab.com/gitlab-org/gitlab/-/issues + + + https://gitlab.com/gitlab-org/gitlab/issues + + + https://gitlab.com/gitlab-org/gitlab/-/merge_requests/84669 + + + https://gitlab.com/gitlab-org/gitlab/-/pipelines/511894707 + + + https://gitlab.com/gitlab-com/gl-infra/production/-/issues/6788 + +

+