From 894073304441438c586ed421e14194a280d64968 Mon Sep 17 00:00:00 2001 From: Chris Holdgraf Date: Wed, 22 Feb 2023 18:32:01 +0100 Subject: [PATCH 1/2] FIX: Icon links component is removed when no icon links config --- src/pydata_sphinx_theme/__init__.py | 23 ++++++++++++++++++- .../components/icon-links.html | 8 ++----- tests/check_warnings.py | 1 - tests/test_build.py | 13 ++++++++--- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/pydata_sphinx_theme/__init__.py b/src/pydata_sphinx_theme/__init__.py index 4909e394a..5f3d5d89f 100644 --- a/src/pydata_sphinx_theme/__init__.py +++ b/src/pydata_sphinx_theme/__init__.py @@ -159,6 +159,28 @@ def update_config(app): if "ablog" in app.config.extensions: app.config.__dict__["fontawesome_included"] = True + # Handle icon link shortcuts + shortcuts = [ + ("twitter_url", "fa-brands fa-square-twitter", "Twitter"), + ("bitbucket_url", "fa-brands fa-bitbucket", "Bitbucket"), + ("gitlab_url", "fa-brands fa-square-gitlab", "GitLab"), + ("github_url", "fa-brands fa-square-github", "GitHub"), + ] + # Add extra icon links entries if there were shortcuts present + # TODO: Deprecate this at some point in the future? + for url, icon, name in shortcuts: + if theme_options.get(url): + # This defaults to an empty list so we can always insert + theme_options["icon_links"].insert( + 0, + { + "url": theme_options.get(url), + "icon": icon, + "name": name, + "type": "fontawesome", + }, + ) + def prepare_html_config(app, pagename, templatename, context, doctree): """Prepare some configuration values for the HTML build. @@ -718,7 +740,6 @@ def soup_to_python(soup, only_pages=False): # ... def extract_level_recursive(ul, navs_list): - for li in ul.find_all("li", recursive=False): ref = li.a url = ref["href"] diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/icon-links.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/icon-links.html index 35ec1cc62..23172ad1a 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/icon-links.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/icon-links.html @@ -25,15 +25,11 @@ {%- endif -%} {%- endmacro -%} +{%- if theme_icon_links -%} +{%- endif -%} diff --git a/tests/check_warnings.py b/tests/check_warnings.py index 90df68478..1b08eb5b7 100644 --- a/tests/check_warnings.py +++ b/tests/check_warnings.py @@ -53,7 +53,6 @@ def check_warnings(file): if __name__ == "__main__": - # cast the file to path and resolve to an absolute one file = Path.cwd() / "warnings.txt" diff --git a/tests/test_build.py b/tests/test_build.py index c1d1bc753..bdbf6bb6f 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -918,10 +918,17 @@ def test_empty_templates(sphinx_build_factory): """If a template is empty (e.g., via a config), it should be removed.""" # When configured to be gone, the template should be removed w/ its parent. # ABlog needs to be added so we can test that template rendering works w/ it. - confoverrides = {"html_show_sourcelink": False} + confoverrides = { + "html_show_sourcelink": False, + } sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build() - toc_items = sphinx_build.html_tree("page1.html").select(".toc-item") - assert not any(ii.select(".tocsection.sourcelink") for ii in toc_items) + html = sphinx_build.html_tree("page1.html") + + # We've set this to fase in the config so the template shouldn't show up at all + assert not html.select(".tocsection.sourcelink") + + # Should not be any icon link wrapper because none are given in conf + assert not html.select(".navbar-icon-links") def test_translations(sphinx_build_factory): From c24a81e0653ead133e77eaf31dc627fc3a4fac3f Mon Sep 17 00:00:00 2001 From: Chris Holdgraf Date: Thu, 23 Feb 2023 16:12:07 +0100 Subject: [PATCH 2/2] Fixing tests --- tests/test_build/sidebar_subpage.html | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_build/sidebar_subpage.html b/tests/test_build/sidebar_subpage.html index 69ef15aeb..38858886c 100644 --- a/tests/test_build/sidebar_subpage.html +++ b/tests/test_build/sidebar_subpage.html @@ -46,10 +46,6 @@ `); -