Skip to content

Commit 76713c3

Browse files
Cadairdrammock
andauthored
Add the ability to add a center section to the footer (#1432)
* Add a center section for the footer * Add docs for footer_center * Add a test site for the center footer * test it in our own docs * remove new test site * add footer test --------- Co-authored-by: Daniel McCloy <[email protected]>
1 parent eb52ac9 commit 76713c3

File tree

7 files changed

+35
-4
lines changed

7 files changed

+35
-4
lines changed

docs/conf.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@
174174
# "primary_sidebar_end": ["custom-template.html", "sidebar-ethical-ads.html"],
175175
# "article_footer_items": ["test.html", "test.html"],
176176
# "content_footer_items": ["test.html", "test.html"],
177-
# "footer_start": ["test.html", "test.html"],
177+
"footer_start": ["copyright.html"],
178+
"footer_center": ["sphinx-version.html"],
178179
# "secondary_sidebar_items": ["page-toc.html"], # Remove the source buttons
179180
"switcher": {
180181
"json_url": json_url,

docs/user_guide/layout.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ Footer
488488
Located in ``sections/footer.html``.
489489

490490
The footer is just below a page's main content, and is configured in ``conf.py``
491-
with ``html_theme_options['footer_start']`` and ``html_theme_options['footer_end']``.
491+
with ``html_theme_options['footer_start']``, ``html_theme_options['footer_center']`` and ``html_theme_options['footer_end']``.
492492

493-
By default, ``footer_end`` is empty, and ``footer_start`` has the following templates:
493+
By default, ``footer_center`` is empty, and ``footer_start`` and ``footer_end`` have the following templates:
494494

495495
.. code-block:: python
496496

src/pydata_sphinx_theme/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def update_and_remove_templates(
190190
"theme_article_footer_items",
191191
"theme_content_footer_items",
192192
"theme_footer_start",
193+
"theme_footer_center",
193194
"theme_footer_end",
194195
"theme_secondary_sidebar_items",
195196
"theme_primary_sidebar_end",

src/pydata_sphinx_theme/assets/styles/sections/_footer.scss

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@
1010
}
1111

1212
.footer-items__start,
13+
.footer-items__center,
1314
.footer-items__end {
1415
display: flex;
1516
flex-direction: column;
1617
gap: 0.5rem;
1718
justify-content: center;
19+
flex-grow: 1;
20+
}
21+
22+
.footer-items__center {
23+
text-align: center;
1824
}
1925

2026
.footer-items__end {
21-
margin-left: auto;
2227
text-align: end;
2328
}
2429

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/sections/footer.html

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
{% endfor %}
88
</div>
99
{% endif %}
10+
{% if theme_footer_center %}
11+
<div class="footer-items__center">
12+
{% for item in theme_footer_center %}
13+
<div class="footer-item">{% include item %}</div>
14+
{% endfor %}
15+
</div>
16+
{% endif %}
1017
{% if theme_footer_end %}
1118
<div class="footer-items__end">
1219
{% for item in theme_footer_end %}

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/theme.conf

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ article_footer_items =
4747
content_footer_items =
4848
primary_sidebar_end = sidebar-ethical-ads.html
4949
footer_start = copyright.html, sphinx-version.html
50+
footer_center =
5051
footer_end = theme-version.html
5152
secondary_sidebar_items = page-toc.html, edit-this-page.html, sourcelink.html
5253
show_version_warning_banner = False

tests/test_build.py

+16
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,22 @@ def test_included_toc(sphinx_build_factory) -> None:
418418
assert included_page_html is not None
419419

420420

421+
def test_footer(sphinx_build_factory) -> None:
422+
"""Test for expected footer contents."""
423+
overrides = {
424+
"html_theme_options.footer_start": ["copyright.html"],
425+
"html_theme_options.footer_center": ["sphinx-version.html"],
426+
}
427+
sphinx_build = sphinx_build_factory("base", confoverrides=overrides).build()
428+
index_html = sphinx_build.html_tree("index.html")
429+
footer_sta = index_html.select("div.footer-items__start")[0]
430+
footer_ctr = index_html.select("div.footer-items__center")[0]
431+
footer_end = index_html.select("div.footer-items__end")[0]
432+
assert "Pydata community" in footer_sta.text
433+
assert "Created using" in footer_ctr.text
434+
assert "Built with the" in footer_end.text
435+
436+
421437
# html contexts for `show_edit_button`
422438

423439
# these are "good" context fragments that should yield a working link

0 commit comments

Comments
 (0)