Skip to content

Commit 469e908

Browse files
westurnerpre-commit-ci[bot]gabalafoudrammock
authored
Make icon links and link shortening optional (#2109)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: gabalafou <[email protected]> Co-authored-by: Daniel McCloy <[email protected]>
1 parent b7ea8ac commit 469e908

File tree

5 files changed

+87
-2
lines changed

5 files changed

+87
-2
lines changed

src/pydata_sphinx_theme/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def update_config(app):
4444
raise ExtensionError(
4545
"`icon_links` must be a list of dictionaries, you provided "
4646
f"type {type(theme_options.get('icon_links'))}."
47+
"If you wish to disable this feature, either do not provide "
48+
"a value (leave undefined), or set to an empty list."
4749
)
4850

4951
# 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]:
282284

283285
app.add_html_theme("pydata_sphinx_theme", str(theme_path))
284286

285-
app.add_post_transform(short_link.ShortenLinkTransform)
287+
theme_options = utils.get_theme_options_dict(app)
288+
if theme_options.get("shorten_urls"):
289+
app.add_post_transform(short_link.ShortenLinkTransform)
286290

287291
app.connect("builder-inited", translator.setup_translators)
288292
app.connect("builder-inited", update_config)

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/theme.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ logo_link =
3737
surface_warnings = True
3838
back_to_top_button = True
3939
search_as_you_type = False
40+
shorten_urls = True
4041

4142
# Template placement in theme layouts
4243
navbar_start = navbar-logo

tests/test_build.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,10 @@ def test_theme_switcher(sphinx_build_factory, file_regression) -> None:
844844

845845
def test_shorten_link(sphinx_build_factory, file_regression) -> None:
846846
"""Regression test for "edit on <provider>" link shortening."""
847-
sphinx_build = sphinx_build_factory("base").build()
847+
confoverrides = {
848+
"html_theme_options": {"shorten_urls": True},
849+
}
850+
sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build()
848851

849852
github = sphinx_build.html_tree("page1.html").select(".github-container")[0]
850853
file_regression.check(github.prettify(), basename="github_links", extension=".html")
@@ -853,6 +856,24 @@ def test_shorten_link(sphinx_build_factory, file_regression) -> None:
853856
file_regression.check(gitlab.prettify(), basename="gitlab_links", extension=".html")
854857

855858

859+
def test_dont_shorten_link(sphinx_build_factory, file_regression) -> None:
860+
"""Regression test for setting shorten_urls to false ."""
861+
confoverrides = {
862+
"html_theme_options": {"shorten_urls": False},
863+
}
864+
sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build()
865+
866+
github = sphinx_build.html_tree("page1.html").select(".github-container")[0]
867+
file_regression.check(
868+
github.prettify(), basename="github_links_not_shortened", extension=".html"
869+
)
870+
871+
gitlab = sphinx_build.html_tree("page1.html").select(".gitlab-container")[0]
872+
file_regression.check(
873+
gitlab.prettify(), basename="gitlab_links_not_shortened", extension=".html"
874+
)
875+
876+
856877
def test_math_header_item(sphinx_build_factory, file_regression) -> None:
857878
"""Regression test for math items in a header title."""
858879
sphinx_build = sphinx_build_factory("base").build()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div class="github-container docutils container">
2+
<p>
3+
<a class="reference external" href="https://github.com">
4+
https://github.com
5+
</a>
6+
<a class="reference external" href="https://github.com/pydata">
7+
https://github.com/pydata
8+
</a>
9+
<a class="reference external" href="https://github.com/pydata/pydata-sphinx-theme">
10+
https://github.com/pydata/pydata-sphinx-theme
11+
</a>
12+
<a class="reference external" href="https://github.com/pydata/pydata-sphinx-theme/pull/1012">
13+
https://github.com/pydata/pydata-sphinx-theme/pull/1012
14+
</a>
15+
<a class="reference external" href="https://github.com/orgs/pydata/projects/2">
16+
https://github.com/orgs/pydata/projects/2
17+
</a>
18+
</p>
19+
</div>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<div class="gitlab-container docutils container">
2+
<p>
3+
<a class="reference external" href="https://gitlab.com">
4+
https://gitlab.com
5+
</a>
6+
<a class="reference external" href="https://gitlab.com/gitlab-org">
7+
https://gitlab.com/gitlab-org
8+
</a>
9+
<a class="reference external" href="https://gitlab.com/gitlab-org/gitlab">
10+
https://gitlab.com/gitlab-org/gitlab
11+
</a>
12+
<a class="reference external" href="https://gitlab.com/gitlab-org/gitlab/-/issues/375583">
13+
https://gitlab.com/gitlab-org/gitlab/-/issues/375583
14+
</a>
15+
<a class="reference external" href="https://gitlab.com/gitlab-org/gitlab/issues/375583">
16+
https://gitlab.com/gitlab-org/gitlab/issues/375583
17+
</a>
18+
<a class="reference external" href="https://gitlab.com/gitlab-org/gitlab/-/issues/">
19+
https://gitlab.com/gitlab-org/gitlab/-/issues/
20+
</a>
21+
<a class="reference external" href="https://gitlab.com/gitlab-org/gitlab/issues/">
22+
https://gitlab.com/gitlab-org/gitlab/issues/
23+
</a>
24+
<a class="reference external" href="https://gitlab.com/gitlab-org/gitlab/-/issues">
25+
https://gitlab.com/gitlab-org/gitlab/-/issues
26+
</a>
27+
<a class="reference external" href="https://gitlab.com/gitlab-org/gitlab/issues">
28+
https://gitlab.com/gitlab-org/gitlab/issues
29+
</a>
30+
<a class="reference external" href="https://gitlab.com/gitlab-org/gitlab/-/merge_requests/84669">
31+
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/84669
32+
</a>
33+
<a class="reference external" href="https://gitlab.com/gitlab-org/gitlab/-/pipelines/511894707">
34+
https://gitlab.com/gitlab-org/gitlab/-/pipelines/511894707
35+
</a>
36+
<a class="reference external" href="https://gitlab.com/gitlab-com/gl-infra/production/-/issues/6788">
37+
https://gitlab.com/gitlab-com/gl-infra/production/-/issues/6788
38+
</a>
39+
</p>
40+
</div>

0 commit comments

Comments
 (0)