mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
Order branches
This commit is contained in:
parent
4dd0506da2
commit
3c434f4efe
3 changed files with 29 additions and 8 deletions
|
@ -9,7 +9,7 @@ window.addEventListener("load", function() {
|
||||||
if (branch === documentBranch) {
|
if (branch === documentBranch) {
|
||||||
option.setAttribute("selected", "");
|
option.setAttribute("selected", "");
|
||||||
}
|
}
|
||||||
select.appendChild(option);
|
select.prepend(option);
|
||||||
}
|
}
|
||||||
select.addEventListener("change", function() {
|
select.addEventListener("change", function() {
|
||||||
if (select.value !== documentBranch) {
|
if (select.value !== documentBranch) {
|
||||||
|
|
|
@ -11,14 +11,13 @@ window.addEventListener("load", function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let nav = document.querySelector("nav");
|
let nav = document.querySelector("nav");
|
||||||
let sections = new Array();
|
let sections = [[document.querySelector("main"), null]];
|
||||||
sections.push([document.querySelector("main"), null]);
|
|
||||||
for (let section of document.querySelectorAll("section")) {
|
for (let section of document.querySelectorAll("section")) {
|
||||||
let id = section.getAttribute("id");
|
let id = section.getAttribute("id");
|
||||||
let link = nav.querySelector("a[href=\\#" + id.replace(/\//g, "\\/") + "]");
|
let link = nav.querySelector("a[href=\\#" + id.replace(/\//g, "\\/") + "]");
|
||||||
if (link !== null) {
|
if (link !== null) {
|
||||||
link = link.parentElement;
|
link = link.parentElement;
|
||||||
link.classList.remove("active")
|
link.classList.remove("active");
|
||||||
sections.push([section, link]);
|
sections.push([section, link]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@ POSTPROCESSOR_EXE = os.path.join(TOOLS_PATH, "postprocessor.py")
|
||||||
PANDOC_EXE = "pandoc"
|
PANDOC_EXE = "pandoc"
|
||||||
PANDOC_DOWNLOAD = ("https://github.com/jgm/pandoc/releases/download/"
|
PANDOC_DOWNLOAD = ("https://github.com/jgm/pandoc/releases/download/"
|
||||||
"2.9.2/pandoc-2.9.2-1-amd64.deb")
|
"2.9.2/pandoc-2.9.2-1-amd64.deb")
|
||||||
|
BRANCH_ORDERING = [ # Format: (REGEX, ORDER, DEFAULT)
|
||||||
|
(r'v?\d+(?:\.\d+)*', 0, True),
|
||||||
|
(r'.*', 1, False)]
|
||||||
|
|
||||||
|
|
||||||
def convert_doc(src_path, to_path, branch, branches):
|
def convert_doc(src_path, to_path, branch, branches):
|
||||||
|
@ -47,7 +50,7 @@ def convert_doc(src_path, to_path, branch, branches):
|
||||||
"--toc-depth=4",
|
"--toc-depth=4",
|
||||||
"--filter=%s" % os.path.abspath(FILTER_EXE),
|
"--filter=%s" % os.path.abspath(FILTER_EXE),
|
||||||
"--variable=branch=%s" % branch,
|
"--variable=branch=%s" % branch,
|
||||||
*["--variable=branches=%s" % b for b in branches]],
|
*("--variable=branches=%s" % b for b in branches)],
|
||||||
check=True, cwd=os.path.dirname(TEMPLATE_PATH))
|
check=True, cwd=os.path.dirname(TEMPLATE_PATH))
|
||||||
with open(to_path, "rb+") as f:
|
with open(to_path, "rb+") as f:
|
||||||
data = subprocess.run([POSTPROCESSOR_EXE], input=f.read(),
|
data = subprocess.run([POSTPROCESSOR_EXE], input=f.read(),
|
||||||
|
@ -73,6 +76,25 @@ def natural_sort_key(s):
|
||||||
for part in re.split(r"(\d+)", s)]
|
for part in re.split(r"(\d+)", s)]
|
||||||
|
|
||||||
|
|
||||||
|
def sort_branches(branches):
|
||||||
|
branches = list(branches)
|
||||||
|
order_least = min(order for _, order, _ in BRANCH_ORDERING) - 1
|
||||||
|
for i, branch in enumerate(branches):
|
||||||
|
for regex, order, default in BRANCH_ORDERING:
|
||||||
|
if re.fullmatch(regex, branch):
|
||||||
|
branches[i] = (order, natural_sort_key(branch), default,
|
||||||
|
branch)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
branches[i] = (order_least, natural_sort_key(branch), False,
|
||||||
|
branch)
|
||||||
|
branches.sort()
|
||||||
|
default_branch = [
|
||||||
|
None, *(branch for _, _, _, branch in branches),
|
||||||
|
*(branch for _, _, default, branch in branches if default)][-1]
|
||||||
|
return [branch for _, _, _, branch in branches], default_branch
|
||||||
|
|
||||||
|
|
||||||
def run_git(*args):
|
def run_git(*args):
|
||||||
config_args = []
|
config_args = []
|
||||||
for key, value in GIT_CONFIG.items():
|
for key, value in GIT_CONFIG.items():
|
||||||
|
@ -116,7 +138,6 @@ def main():
|
||||||
run_git_fetch_and_restart_if_changed(remote_commits, target_branch)
|
run_git_fetch_and_restart_if_changed(remote_commits, target_branch)
|
||||||
branches = [ref[len("refs/remotes/%s/" % REMOTE):] for ref in run_git(
|
branches = [ref[len("refs/remotes/%s/" % REMOTE):] for ref in run_git(
|
||||||
"rev-parse", "--symbolic-full-name", "--remotes=%s" % REMOTE)]
|
"rev-parse", "--symbolic-full-name", "--remotes=%s" % REMOTE)]
|
||||||
branches.sort(key=natural_sort_key, reverse=True)
|
|
||||||
os.makedirs(TARGET_DIR, exist_ok=True)
|
os.makedirs(TARGET_DIR, exist_ok=True)
|
||||||
for path in glob.iglob(os.path.join(TARGET_DIR, "*.html")):
|
for path in glob.iglob(os.path.join(TARGET_DIR, "*.html")):
|
||||||
run_git("rm", "--", path)
|
run_git("rm", "--", path)
|
||||||
|
@ -130,14 +151,15 @@ def main():
|
||||||
else:
|
else:
|
||||||
branches.remove(branch)
|
branches.remove(branch)
|
||||||
checkout(target_branch)
|
checkout(target_branch)
|
||||||
|
branches, default_branch = sort_branches(branches)
|
||||||
for branch, src_path in branch_docs.items():
|
for branch, src_path in branch_docs.items():
|
||||||
to_path = os.path.join(TARGET_DIR, "%s.html" % branch)
|
to_path = os.path.join(TARGET_DIR, "%s.html" % branch)
|
||||||
convert_doc(src_path, to_path, branch, branches)
|
convert_doc(src_path, to_path, branch, branches)
|
||||||
run_git("add", "--", to_path)
|
run_git("add", "--", to_path)
|
||||||
if branches:
|
if default_branch:
|
||||||
index_path = os.path.join(TARGET_DIR, "index.html")
|
index_path = os.path.join(TARGET_DIR, "index.html")
|
||||||
with open(index_path, "w") as f:
|
with open(index_path, "w") as f:
|
||||||
f.write(make_index_html(branches[0]))
|
f.write(make_index_html(default_branch))
|
||||||
run_git("add", "--", index_path)
|
run_git("add", "--", index_path)
|
||||||
with contextlib.suppress(subprocess.CalledProcessError):
|
with contextlib.suppress(subprocess.CalledProcessError):
|
||||||
run_git("diff", "--cached", "--quiet")
|
run_git("diff", "--cached", "--quiet")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue