Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,28 @@ function debounce(callback, wait) {
*/
async function setupAnnouncementBanner() {
const banner = document.querySelector(".bd-header-announcement");

// check if banner has been dismissed recently
const dismiss_date_str = JSON.parse(
localStorage.getItem("pst_announcement_banner_pref") || "{}",
)["closed"];
if (dismiss_date_str != null) {
const dismiss_date = new Date(dismiss_date_str);
const now = new Date();
const milliseconds_in_a_day = 24 * 60 * 60 * 1000;
const days_passed = (now - dismiss_date) / milliseconds_in_a_day;
const timeout_in_days = 14;
if (days_passed < timeout_in_days) {
console.info(
`[PST] Suppressing announcement banner; was dismissed ${Math.floor(
days_passed,
)} day(s) ago`,
);
banner.remove();
return;
}
}

const { pstAnnouncementUrl } = banner ? banner.dataset : null;

if (!pstAnnouncementUrl) {
Expand All @@ -947,6 +969,31 @@ async function setupAnnouncementBanner() {
console.log(`[PST]: Failed to load announcement at: ${pstAnnouncementUrl}`);
console.error(_error);
}

// Add close button
console.debug("[PST] Adding close button to announcement banner");
const close_btn = document.createElement("a");
close_btn.classList = "ms-3 my-1 align-baseline";
const close_x = document.createElement("i");
close_btn.append(close_x);
close_x.classList = "fa-solid fa-xmark";
close_btn.onclick = DismissAnnouncementBannerAndStorePref;
banner.append(close_btn);
}

async function DismissAnnouncementBannerAndStorePref(event) {
const banner = document.querySelector(".bd-header-announcement");
banner.remove();
const now = new Date();
const banner_pref = JSON.parse(
localStorage.getItem("pst_announcement_banner_pref") || "{}",
);
console.debug(`[PST] Dismissing the announcement banner starting ${now}.`);
banner_pref["closed"] = now.toISOString();
localStorage.setItem(
"pst_announcement_banner_pref",
JSON.stringify(banner_pref),
);
}

/*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
// Ensure there is enough contrast against the background
a {
color: var(--pst-color-link-higher-contrast);

&:hover {
// applying the same style as the SD "buttons"
@include link-style-hover;

cursor: pointer;
}
}

// The "Switch to stable version" link (styled like a button)
Expand Down
Loading