Skip to content

Commit

Permalink
Do not show announcement banner if announcement contents are empty (#…
Browse files Browse the repository at this point in the history
…1703)

* Do not show announcement banner if announcement contents are empty

Also add documentation about updating and removing announcement banners.

* dedent

* Apply suggestions from code review

---------

Co-authored-by: Daniel McCloy <[email protected]>
  • Loading branch information
melissawm and drammock authored Feb 12, 2024
1 parent 355d612 commit 7de2c04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/user_guide/announcements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ For example, the following configuration tells the theme to load the ``custom-te
"announcement": "https://github.com/pydata/pydata-sphinx-theme/raw/main/docs/_templates/custom-template.html",
}
Update or remove announcement banner
------------------------------------

To update or remove the announcement banner, you can change the value of
``html_theme_options["announcement"]`` in your ``conf.py`` or you can edit the
contents of the ``custom-template.html`` file directly. For example, if you have a
temporary announcement that you want to remove without rebuilding your
documentation pages, you can use an empty ``custom-template.html`` file and the
banner will be hidden.

.. _version-warning-banners:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
fetch("{{ theme_announcement }}")
.then(res => {return res.text();})
.then(data => {
if (data.length === 0) {
console.log("[PST]: Empty announcement at: {{ theme_announcement }}");
return;
}
div = document.querySelector(".bd-header-announcement");
div.classList.add(...{{ header_classes | tojson }});
div.innerHTML = `<div class="bd-header-announcement__content">${data}</div>`;
Expand Down

0 comments on commit 7de2c04

Please sign in to comment.