From 7de2c042d42c003e6708f56d09cb755550ed7c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melissa=20Weber=20Mendon=C3=A7a?= Date: Mon, 12 Feb 2024 20:38:38 -0300 Subject: [PATCH] Do not show announcement banner if announcement contents are empty (#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 --- docs/user_guide/announcements.rst | 9 +++++++++ .../theme/pydata_sphinx_theme/sections/announcement.html | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/docs/user_guide/announcements.rst b/docs/user_guide/announcements.rst index d86abb295..edac65ff9 100644 --- a/docs/user_guide/announcements.rst +++ b/docs/user_guide/announcements.rst @@ -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: diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/sections/announcement.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/sections/announcement.html index dbe094fca..b53c73dbb 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/sections/announcement.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/sections/announcement.html @@ -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 = `
${data}
`;