Skip to content

Commit 96bd58c

Browse files
committed
Fix display of local announcement banner
Closes pydatagh-1817
1 parent 2b276c3 commit 96bd58c

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/sections/announcement.html

+28-23
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,9 @@
22
{% set header_classes = ["bd-header-announcement", "container-fluid", "init"] %}
33
{% set is_remote=theme_announcement.startswith("http") %}
44
{# If we are remote, add a script to make an HTTP request for the value on page load #}
5-
{%- if is_remote %}
65
<script>
7-
document.write(`<aside class="bd-header-announcement d-print-none" aria-label="{{ banner_label }}"></aside>`);
8-
fetch("{{ theme_announcement }}")
9-
.then(res => {return res.text();})
10-
.then(data => {
11-
if (data.length === 0) {
12-
console.log("[PST]: Empty announcement at: {{ theme_announcement }}");
13-
return;
14-
}
15-
div = document.querySelector(".bd-header-announcement");
16-
div.classList.add(...{{ header_classes | tojson }});
17-
div.innerHTML = `<div class="bd-header-announcement__content">${data}</div>`;
6+
function setAnnouncementHeight() {
7+
const div = document.querySelector(".bd-header-announcement");
188
// At least 3rem height
199
const autoHeight = Math.min(
2010
div.offsetHeight,
@@ -36,15 +26,30 @@
3626
div.style.setProperty("min-height", "3rem");
3727
}, 320);
3828
}, 10);
39-
})
40-
.catch(error => {
41-
console.log("[PST]: Failed to load announcement at: {{ theme_announcement }}");
42-
});
29+
}
30+
is_remote = {{ is_remote | tojson }};
31+
if (is_remote) {
32+
document.write(`<aside class="bd-header-announcement d-print-none" aria-label="{{ banner_label }}"></aside>`);
33+
fetch("{{ theme_announcement }}")
34+
.then(res => {return res.text();})
35+
.then(data => {
36+
if (data.length === 0) {
37+
console.log("[PST]: Empty announcement at: {{ theme_announcement }}");
38+
return;
39+
}
40+
div = document.querySelector(".bd-header-announcement");
41+
div.classList.add(...{{ header_classes | tojson }});
42+
div.innerHTML = `<div class="bd-header-announcement__content">${data}</div>`;
43+
setAnnouncementHeight();
44+
})
45+
.catch(error => {
46+
console.log("[PST]: Failed to load announcement at: {{ theme_announcement }}");
47+
});
48+
} else {
49+
document.write(`<aside class="{{ header_classes | join(' ') }} bd-header-announcement" aria-label="{{ banner_label }}">
50+
<div class="bd-header-announcement__content">{{ theme_announcement }}</div>
51+
</aside>`)
52+
console.log("[PST]: Using local announcement.")
53+
setAnnouncementHeight();
54+
}
4355
</script>
44-
{#- if announcement text is not remote, populate announcement w/ local content -#}
45-
{%- else %}
46-
<aside class="{{ header_classes | join(' ') }} bd-header-announcement"
47-
aria-label="{{ banner_label }}">
48-
<div class="bd-header-announcement__content">{{ theme_announcement }}</div>
49-
</aside>
50-
{% endif %}

0 commit comments

Comments
 (0)