Skip to content

Commit

Permalink
Add the ability to add a center section to the footer (#1432)
Browse files Browse the repository at this point in the history
* 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 <dan@mccloy.info>
  • Loading branch information
Cadair and drammock authored Sep 8, 2023
1 parent eb52ac9 commit 76713c3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
# "primary_sidebar_end": ["custom-template.html", "sidebar-ethical-ads.html"],
# "article_footer_items": ["test.html", "test.html"],
# "content_footer_items": ["test.html", "test.html"],
# "footer_start": ["test.html", "test.html"],
"footer_start": ["copyright.html"],
"footer_center": ["sphinx-version.html"],
# "secondary_sidebar_items": ["page-toc.html"], # Remove the source buttons
"switcher": {
"json_url": json_url,
Expand Down
4 changes: 2 additions & 2 deletions docs/user_guide/layout.rst
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ Footer
Located in ``sections/footer.html``.

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

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

.. code-block:: python
Expand Down
1 change: 1 addition & 0 deletions src/pydata_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def update_and_remove_templates(
"theme_article_footer_items",
"theme_content_footer_items",
"theme_footer_start",
"theme_footer_center",
"theme_footer_end",
"theme_secondary_sidebar_items",
"theme_primary_sidebar_end",
Expand Down
7 changes: 6 additions & 1 deletion src/pydata_sphinx_theme/assets/styles/sections/_footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
}

.footer-items__start,
.footer-items__center,
.footer-items__end {
display: flex;
flex-direction: column;
gap: 0.5rem;
justify-content: center;
flex-grow: 1;
}

.footer-items__center {
text-align: center;
}

.footer-items__end {
margin-left: auto;
text-align: end;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
{% endfor %}
</div>
{% endif %}
{% if theme_footer_center %}
<div class="footer-items__center">
{% for item in theme_footer_center %}
<div class="footer-item">{% include item %}</div>
{% endfor %}
</div>
{% endif %}
{% if theme_footer_end %}
<div class="footer-items__end">
{% for item in theme_footer_end %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ article_footer_items =
content_footer_items =
primary_sidebar_end = sidebar-ethical-ads.html
footer_start = copyright.html, sphinx-version.html
footer_center =
footer_end = theme-version.html
secondary_sidebar_items = page-toc.html, edit-this-page.html, sourcelink.html
show_version_warning_banner = False
Expand Down
16 changes: 16 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,22 @@ def test_included_toc(sphinx_build_factory) -> None:
assert included_page_html is not None


def test_footer(sphinx_build_factory) -> None:
"""Test for expected footer contents."""
overrides = {
"html_theme_options.footer_start": ["copyright.html"],
"html_theme_options.footer_center": ["sphinx-version.html"],
}
sphinx_build = sphinx_build_factory("base", confoverrides=overrides).build()
index_html = sphinx_build.html_tree("index.html")
footer_sta = index_html.select("div.footer-items__start")[0]
footer_ctr = index_html.select("div.footer-items__center")[0]
footer_end = index_html.select("div.footer-items__end")[0]
assert "Pydata community" in footer_sta.text
assert "Created using" in footer_ctr.text
assert "Built with the" in footer_end.text


# html contexts for `show_edit_button`

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

0 comments on commit 76713c3

Please sign in to comment.