-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy documentation to versioned subdirectories
- Loading branch information
Showing
5 changed files
with
124 additions
and
4 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
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,12 @@ | ||
#version-selector { | ||
float: left; | ||
display: flex; | ||
align-items: center; | ||
margin: 0 10px; | ||
} | ||
|
||
#version-selector > select { | ||
width: auto; | ||
height: auto; | ||
padding: 1px; | ||
} |
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,71 @@ | ||
window.addEventListener("DOMContentLoaded", function() { | ||
function normalizePath(path) { | ||
var normalized = []; | ||
path.split("/").forEach(function(bit, i) { | ||
if (bit === "." || (bit === "" && i !== 0)) { | ||
return; | ||
} else if (bit === "..") { | ||
if (normalized.length === 1 && normalized[0] === "") { | ||
// We must be trying to .. past the root! | ||
throw new Error("invalid path"); | ||
} else if (normalized.length === 0 || | ||
normalized[normalized.length - 1] === "..") { | ||
normalized.push(".."); | ||
} else { | ||
normalized.pop(); | ||
} | ||
} else { | ||
normalized.push(bit); | ||
} | ||
}); | ||
return normalized.join("/"); | ||
} | ||
|
||
// `base_url` comes from the base.html template for this theme. | ||
var REL_BASE_URL = base_url; | ||
var ABS_BASE_URL = normalizePath(window.location.pathname + "/" + | ||
REL_BASE_URL); | ||
var CURRENT_VERSION = ABS_BASE_URL.split("/").pop(); | ||
|
||
function makeSelect(options, selected) { | ||
var select = document.createElement("select"); | ||
select.classList.add("form-control"); | ||
|
||
options.forEach(function(i) { | ||
var option = new Option(i.text, i.value, undefined, | ||
i.value === selected); | ||
select.add(option); | ||
}); | ||
|
||
return select; | ||
} | ||
|
||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", REL_BASE_URL + "/../versions.json"); | ||
xhr.onload = function() { | ||
var versions = JSON.parse(this.responseText); | ||
|
||
var realVersion = versions.find(function(i) { | ||
return i.version === CURRENT_VERSION || | ||
i.aliases.includes(CURRENT_VERSION); | ||
}).version; | ||
|
||
var select = makeSelect(versions.map(function(i) { | ||
return {text: i.title, value: i.version}; | ||
}), realVersion); | ||
select.addEventListener("change", function(event) { | ||
window.location.href = REL_BASE_URL + "/../" + this.value; | ||
}); | ||
|
||
var container = document.createElement("div"); | ||
container.id = "version-selector"; | ||
container.appendChild(select); | ||
|
||
var title = document.querySelector("div.navbar-header"); | ||
var height = window.getComputedStyle(title).getPropertyValue("height"); | ||
container.style.height = height; | ||
|
||
title.appendChild(container); | ||
}; | ||
xhr.send(); | ||
}); |
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,32 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
import json | ||
import re | ||
import subprocess | ||
from packaging.version import Version | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser( | ||
description="Deploy mettle's documentation to the gh-pages branch" | ||
) | ||
parser.add_argument('version', help='the current mettle version number') | ||
|
||
args = parser.parse_args() | ||
|
||
v = Version(args.version) | ||
alias = 'dev' if v.is_devrelease else 'latest' | ||
title = '{} ({})'.format(v.base_version, alias) | ||
short_version = '{}.{}'.format(*v.release[:2]) | ||
|
||
info = json.loads(subprocess.check_output( | ||
['mike', 'list', '-j', alias], | ||
universal_newlines=True | ||
)) | ||
if info['version'] != short_version: | ||
t = re.sub(r' \({}\)$'.format(re.escape(alias)), '', | ||
info['title']) | ||
subprocess.check_call(['mike', 'retitle', info['version'], t]) | ||
|
||
subprocess.check_call(['mike', 'deploy', '-ut', title, | ||
short_version, alias]) |