-
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.
add version switcher (cleaner diff this time)
- Loading branch information
Showing
4 changed files
with
155 additions
and
3 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,97 @@ | ||
[ | ||
{ | ||
"name": "v0.6.3 (latest)", | ||
"version": "latest", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.6.2", | ||
"version": "v0.6.2", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.6.1", | ||
"version": "v0.6.1", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.6.0", | ||
"version": "v0.6.0", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.5.2", | ||
"version": "v0.5.2", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.5.1", | ||
"version": "v0.5.1", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.5.0", | ||
"version": "v0.5.0", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.4.3", | ||
"version": "v0.4.3", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.4.2", | ||
"version": "v0.4.2", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.4.1", | ||
"version": "v0.4.1", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.4.0", | ||
"version": "v0.4.0", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.3.2", | ||
"version": "v0.3.2", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.3.1", | ||
"version": "v0.3.1", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.3.0", | ||
"version": "v0.3.0", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.2.2", | ||
"version": "v0.2.2", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.2.1", | ||
"version": "v0.2.1", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.2.0", | ||
"version": "v0.2.0", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.1.1", | ||
"version": "v0.1.1", | ||
"language": "en" | ||
}, | ||
{ | ||
"name": "v0.1.0", | ||
"version": "v0.1.0", | ||
"language": "en" | ||
} | ||
] |
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,50 @@ | ||
<div class="dropdown"> | ||
<button type="button" class="btn btn-primary btn-sm navbar-btn dropdown-toggle" id="switcher_button" data-toggle="dropdown"> | ||
{{ switcher_prefix }}{{ release }} | ||
<span class="caret"></span> | ||
</button> | ||
<div id="switcher" class="dropdown-menu list-group-flush py-0" aria-labelledby="switcher_button"> | ||
<!-- dropdown will be populated by javascript on page load --> | ||
</div> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
// Function to construct the target URL from the JSON components | ||
function buildURL(template, entry) { | ||
// | ||
var parts = template.split(/[\{\}]/); | ||
version_ix = parts.indexOf("version"); | ||
language_ix = parts.indexOf("language"); | ||
if (version_ix >= 0) { | ||
parts[version_ix] = entry.version; | ||
} | ||
if (language_ix >= 0) { | ||
parts[language_ix] = entry.language; | ||
} | ||
return parts.join(""); | ||
} | ||
// Function to populate the (release, language) version switcher | ||
(function () { | ||
// get JSON config | ||
$.getJSON("{{ switcher_json_url }}", function(data, textStatus, jqXHR) { | ||
// create the nodes first (before AJAX calls) to ensure the order is | ||
// correct (for now, links will go to doc version homepage) | ||
$.each(data, function(index, entry) { | ||
entry.url = buildURL("{{ switcher_template_url }}", entry); | ||
$("#switcher").append(`<a class="list-group-item list-group-item-action py-1" href="${entry.url}">${entry.name}</a>`); | ||
}); | ||
// see if the current page exists in the other versions of the docs | ||
$.each(data, function(index, entry) { | ||
let filePath = "{{ pagename }}.html"; | ||
$.ajax({ | ||
type: 'HEAD', | ||
url: `${entry.url}${filePath}`, | ||
// update the target URL if it exists | ||
success: function() { | ||
$("#switcher").children()[index].setAttribute("href", `${entry.url}${filePath}`); | ||
} | ||
}); | ||
}); | ||
}); | ||
})(); | ||
</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