Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Remove icon links component when no icon links given #1209

Merged
merged 3 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/pydata_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,28 @@ def update_config(app):
):
app.config.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",
},
)

# Prepare the logo config dictionary
theme_logo = theme_options.get("logo")
if not theme_logo:
Expand Down Expand Up @@ -720,7 +742,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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@
</li>
{%- endif -%}
{%- endmacro -%}
{%- if theme_icon_links -%}
<ul class="navbar-icon-links navbar-nav"
aria-label="{{ theme_icon_links_label }}">
{%- block icon_link_shortcuts -%}
{{ icon_link_nav_item(theme_github_url, "fa-brands fa-square-github", _("GitHub"), "fontawesome") -}}
{{ icon_link_nav_item(theme_gitlab_url, "fa-brands fa-square-gitlab", _("GitLab"), "fontawesome") -}}
{{ icon_link_nav_item(theme_bitbucket_url, "fa-brands fa-bitbucket", _("Bitbucket"), "fontawesome") -}}
{{ icon_link_nav_item(theme_twitter_url, "fa-brands fa-square-twitter", _("Twitter"), "fontawesome") -}}
{% endblock icon_link_shortcuts -%}
{%- for icon_link in theme_icon_links -%}
{{ icon_link_nav_item(icon_link["url"], icon_link["icon"], icon_link["name"], icon_link.get("type", "fontawesome"), icon_link.get("attributes", {})) -}}
{%- endfor %}
</ul>
{%- endif -%}
1 change: 0 additions & 1 deletion tests/check_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
13 changes: 10 additions & 3 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 0 additions & 4 deletions tests/test_build/sidebar_subpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
`);
</script>
</div>
<div class="navbar-item">
<ul aria-label="Icon Links" class="navbar-icon-links navbar-nav">
</ul>
</div>
</div>
</div>
<div class="sidebar-primary-items__start sidebar-primary__section">
Expand Down