Skip to content

Commit

Permalink
fix version-switcher with dirhtml builder
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Apr 30, 2024
1 parent 30be4d4 commit c65fdb4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,12 @@ var setupSearchButtons = () => {
async function checkPageExistsAndRedirect(event) {
// ensure we don't follow the initial link
event.preventDefault();
let currentFilePath = `${DOCUMENTATION_OPTIONS.pagename}.html`;
let currentFilePath;
if (DOCUMENTATION_OPTIONS.BUILDER == "dirhtml") {
currentFilePath = DOCUMENTATION_OPTIONS.pagename == "index" ? `/` : `${DOCUMENTATION_OPTIONS.pagename}/`;
} else {
currentFilePath = `${DOCUMENTATION_OPTIONS.pagename}.html`;
}
let tryUrl = event.currentTarget.getAttribute("href");
let otherDocsHomepage = tryUrl.replace(currentFilePath, "");
try {
Expand Down Expand Up @@ -372,7 +377,12 @@ async function fetchVersionSwitcherJSON(url) {

// Populate the version switcher from the JSON data
function populateVersionSwitcher(data, versionSwitcherBtns) {
const currentFilePath = `${DOCUMENTATION_OPTIONS.pagename}.html`;
let currentFilePath;
if (DOCUMENTATION_OPTIONS.BUILDER == "dirhtml") {
currentFilePath = DOCUMENTATION_OPTIONS.pagename == "index" ? `/` : `${DOCUMENTATION_OPTIONS.pagename}/`;
} else {
currentFilePath = `${DOCUMENTATION_OPTIONS.pagename}.html`;
}
versionSwitcherBtns.forEach((btn) => {
// Set empty strings by default so that these attributes exist and can be used in CSS selectors
btn.dataset["activeVersionName"] = "";
Expand Down Expand Up @@ -490,7 +500,11 @@ function showVersionWarningBanner(data) {
inner.classList = "sidebar-message";
button.classList =
"btn text-wrap font-weight-bold ms-3 my-1 align-baseline pst-button-link-to-stable-version";
button.href = `${preferredURL}${DOCUMENTATION_OPTIONS.pagename}.html`;
if (DOCUMENTATION_OPTIONS.BUILDER == "dirhtml") {
button.href = DOCUMENTATION_OPTIONS.pagename == "index" ? `/` : `${DOCUMENTATION_OPTIONS.pagename}/`;
} else {
button.href = `${DOCUMENTATION_OPTIONS.pagename}.html`;
}
button.innerText = "Switch to stable version";
button.onclick = checkPageExistsAndRedirect;
// add the version-dependent text
Expand Down

0 comments on commit c65fdb4

Please sign in to comment.