Skip to content

Commit 52cb046

Browse files
authored
project name in navbar if no logo given (#259)
1 parent bdf8224 commit 52cb046

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

pydata_sphinx_theme/docs-navbar.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11

22
<div class="container-xl">
33

4-
{% if logo %}
54
<a class="navbar-brand" href="{{ pathto(master_doc) }}">
6-
<img src="{{ pathto('_static/' + logo, 1) }}" class="logo" alt="logo">
7-
</a>
5+
{% if logo %}
6+
<img src="{{ pathto('_static/' + logo, 1) }}" class="logo" alt="logo" />
7+
{% else %}
8+
<p class="title">{{ project }}</p>
89
{% endif %}
10+
</a>
911
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-menu" aria-controls="navbar-menu" aria-expanded="false" aria-label="Toggle navigation">
1012
<span class="navbar-toggler-icon"></span>
1113
</button>
@@ -47,4 +49,4 @@
4749
{% endif %}
4850
</ul>
4951
</div>
50-
</div>
52+
</div>

tests/sites/base/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# ones.
1414
extensions = []
1515
html_theme = "pydata_sphinx_theme"
16+
html_logo = "emptylogo.png"
1617
html_copy_source = True
1718
html_sourcelink_suffix = ""
1819

tests/sites/base/emptylogo.png

Loading

tests/test_build.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,20 @@ def test_toc_visibility(file_regression, sphinx_build):
8080
# The 3rd level headers should be visible, but not the fourth-level
8181
assert "visible" in index_html.select(".toc-h2 ul")[0].attrs["class"]
8282
assert "visible" not in index_html.select(".toc-h3 ul")[0].attrs["class"]
83+
84+
85+
def test_logo_name(file_regression, sphinx_build):
86+
"""Test that the logo is shown by default, project title if no logo."""
87+
sphinx_build.copy()
88+
89+
# By default logo is shown
90+
sphinx_build.build()
91+
index_html = sphinx_build.get("index.html")
92+
assert index_html.select(".navbar-brand img")
93+
assert not index_html.select(".navbar-brand")[0].text.strip()
94+
sphinx_build.clean()
95+
96+
# Test that setting TOC level visibility works as expected
97+
sphinx_build.build(["-D", "html_logo="])
98+
index_html = sphinx_build.get("index.html")
99+
assert "PyData Tests" in index_html.select(".navbar-brand")[0].text.strip()

0 commit comments

Comments
 (0)