-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Daniel McCloy <[email protected]> Co-authored-by: ThuWangzw <[email protected]> Co-authored-by: Xinran Xu <[email protected]> Co-authored-by: MegChai <[email protected]> Co-authored-by: Chris Holdgraf <[email protected]> Co-authored-by: Joris Van den Bossche <[email protected]>
- Loading branch information
1 parent
102f741
commit af02a6a
Showing
6 changed files
with
333 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[ | ||
{ | ||
"name": "v0.7.1 (stable)", | ||
"version": "0.7.1" | ||
}, | ||
{ | ||
"version": "0.7.0" | ||
}, | ||
{ | ||
"version": "0.6.3" | ||
}, | ||
{ | ||
"version": "0.6.2" | ||
}, | ||
{ | ||
"version": "0.6.1" | ||
}, | ||
{ | ||
"version": "0.6.0" | ||
}, | ||
{ | ||
"version": "0.5.2" | ||
}, | ||
{ | ||
"version": "0.5.1" | ||
}, | ||
{ | ||
"version": "0.5.0" | ||
}, | ||
{ | ||
"version": "0.4.3" | ||
}, | ||
{ | ||
"version": "0.4.2" | ||
}, | ||
{ | ||
"version": "0.4.1" | ||
}, | ||
{ | ||
"version": "0.4.0" | ||
}, | ||
{ | ||
"version": "0.3.2" | ||
}, | ||
{ | ||
"version": "0.3.1" | ||
}, | ||
{ | ||
"version": "0.3.0" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<div class="dropdown" id="version_switcher"> | ||
<button type="button" class="btn btn-primary btn-sm navbar-btn dropdown-toggle" id="version_switcher_button" data-toggle="dropdown"> | ||
{{ theme_switcher.get('version_match') }} <!-- this text may get changed later by javascript --> | ||
<span class="caret"></span> | ||
</button> | ||
<div id="version_switcher_menu" class="dropdown-menu list-group-flush py-0" aria-labelledby="version_switcher_button"> | ||
<!-- dropdown will be populated by javascript on page load --> | ||
</div> | ||
</div> | ||
|
||
<!-- NOTE: this JS must live here (not in our global JS file) because it relies | ||
on being processed by Jinja before it is run (specifically for replacing | ||
variables {{ pagename }} and {{ theme_switcher }}. | ||
--> | ||
|
||
<script type="text/javascript"> | ||
// Construct the target URL from the JSON components | ||
function buildURL(entry) { | ||
var template = "{{ theme_switcher.get('url_template') }}"; // supplied by jinja | ||
template = template.replace("{version}", entry.version); | ||
return template; | ||
} | ||
|
||
// Check if corresponding page path exists in other version of docs | ||
// and, if so, go there instead of the homepage of the other docs version | ||
function checkPageExistsAndRedirect(event) { | ||
const currentFilePath = "{{ pagename }}.html", | ||
tryUrl = event.target.getAttribute("href"); | ||
let otherDocsHomepage = tryUrl.replace(currentFilePath, ""); | ||
$.ajax({ | ||
type: 'HEAD', | ||
url: tryUrl, | ||
// if the page exists, go there | ||
success: function() { | ||
location.href = tryUrl; | ||
} | ||
}).fail(function() { | ||
location.href = otherDocsHomepage; | ||
}); | ||
// this prevents the browser from following the href of the clicked node | ||
// (which is fine because this function takes care of redirecting) | ||
return false; | ||
} | ||
|
||
// Populate the version switcher from the JSON config file | ||
(function () { | ||
$.getJSON("{{ theme_switcher.get('json_url') }}", function(data, textStatus, jqXHR) { | ||
const currentFilePath = "{{ pagename }}.html"; | ||
// create links to the corresponding page in the other docs versions | ||
$.each(data, function(index, entry) { | ||
// if no custom name specified (e.g., "latest"), use version string | ||
if (!("name" in entry)) { | ||
entry.name = entry.version; | ||
} | ||
// create the node | ||
const node = document.createElement("a"); | ||
node.setAttribute("class", "list-group-item list-group-item-action py-1"); | ||
node.textContent = `${entry.name}`; | ||
// get the base URL for that doc version, add the current page's | ||
// path to it, and set as `href` | ||
entry.url = buildURL(entry); | ||
node.setAttribute("href", `${entry.url}${currentFilePath}`); | ||
// on click, AJAX calls will check if the linked page exists before | ||
// trying to redirect, and if not, will redirect to the homepage | ||
// for that version of the docs. | ||
node.onclick = checkPageExistsAndRedirect; | ||
$("#version_switcher_menu").append(node); | ||
// replace dropdown button text with the preferred display name of | ||
// this version, rather than using sphinx's {{ version }} variable. | ||
// also highlight the dropdown entry for the currently-viewed | ||
// version's entry | ||
if (entry.version == "{{ theme_switcher.get('version_match') }}") { | ||
node.classList.add("active"); | ||
$("#version_switcher_button").text(entry.name); | ||
} | ||
}); | ||
}); | ||
})(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters