-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a version selector to the sidebar
This requires a versions.json file to be placed at the root of the SymPy docs repo like { "latest": "1.10", "dev": "1.11.dev" }
- Loading branch information
Showing
3 changed files
with
76 additions
and
1 deletion.
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
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,56 @@ | ||
<!-- Versions Menu. In order to work, there should be a file called versions.json one level up from the documentation listing the "dev" and "latest" version numbers, like | ||
{ | ||
"latest": "1.10", | ||
"dev": "1.11.dev" | ||
} | ||
--> | ||
<div class="sidebar-tree sidebar-versions"> | ||
<h5 class="versions-header">Documentation Version</h4> | ||
</div> | ||
|
||
<!-- Make sure jquery is loaded (we would put this as a separate .js, but it uses jinja templates in some of the variables) --> | ||
<script src="{{ pathto('_static/jquery.js', 1) }}"></script> | ||
<script> | ||
var json_loc = "../{{ pathto('versions.json', 1) }}"; | ||
|
||
function add_version_menu(json_loc) { | ||
var menu = document.createElement("ul"); | ||
var thisversion = "{{ 'dev' if '.dev' in release else 'latest' }}" | ||
$.getJSON(json_loc, {"crossDomain": true}, function(versions) { | ||
for (var key in versions) { | ||
if (key != "latest" && key != "dev") { | ||
console.error("Invalid key in versions.json", key); | ||
} else { | ||
var version = document.createElement("li") | ||
version.className = "sidebar-versions-l1 sidebar-versions-" + key + "-l1"; | ||
if (key == thisversion){ | ||
version.className += " current-version"; | ||
} | ||
var a = document.createElement("a"); | ||
a.className = "reference internal"; | ||
a.innerHTML = "SymPy " + versions[key] + " (" + key + " version)"; | ||
a.title = key + " version"; | ||
a.href = "https://docs.sympy.org/" + key + "/{{ pagename }}.html"; | ||
version.appendChild(a); | ||
menu.appendChild(version); | ||
} | ||
} | ||
}).done(function() { | ||
console.log("versions.json read successfully"); | ||
}).fail(function() { | ||
var version = document.createElement("li") | ||
version.className = "sidebar-versions-l1 sidebar-versions-latest-l1"; | ||
var d = document.createElement("div"); | ||
d.className = "versions-not-found" | ||
d.innerHTML = "Other Versions Not Found"; | ||
d.title = "The version selection menu is only available for the documentation published on docs.sympy.org"; | ||
version.appendChild(d); | ||
menu.appendChild(version); | ||
console.error("Could not read versions.json"); | ||
}).always(function() { | ||
$(".sidebar-versions").append(menu) | ||
}); | ||
}; | ||
|
||
$( document ).ready( add_version_menu(json_loc)); | ||
</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