mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
Add configuration for redirects
This commit is contained in:
parent
b01968d155
commit
138d70fa98
4 changed files with 27 additions and 15 deletions
2
.github/workflows/generate-documentation.yml
vendored
2
.github/workflows/generate-documentation.yml
vendored
|
@ -3,7 +3,7 @@ on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- 'documentation-generator/**'
|
- 'documentation-generator/**'
|
||||||
- DOCUMENTATION.md
|
- redirect.json
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
generate:
|
generate:
|
||||||
|
|
|
@ -9,11 +9,13 @@ Gracefully handles conflicting commits.
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import glob
|
import glob
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import urllib.parse
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
REMOTE = "origin"
|
REMOTE = "origin"
|
||||||
|
@ -22,10 +24,11 @@ GIT_CONFIG = {"protocol.version": "2",
|
||||||
"user.name": "Github Actions"}
|
"user.name": "Github Actions"}
|
||||||
COMMIT_MESSAGE = "Generate documentation"
|
COMMIT_MESSAGE = "Generate documentation"
|
||||||
DOCUMENTATION_SRC = "DOCUMENTATION.md"
|
DOCUMENTATION_SRC = "DOCUMENTATION.md"
|
||||||
|
REDIRECT_CONFIG_PATH = "redirect.json"
|
||||||
SHIFT_HEADING = 1
|
SHIFT_HEADING = 1
|
||||||
TOC_DEPTH = 3
|
TOC_DEPTH = 3
|
||||||
TOOLS_PATH = os.path.dirname(__file__)
|
TOOLS_PATH = os.path.dirname(__file__)
|
||||||
TEMPLATE_INDEX_PATH = os.path.join(TOOLS_PATH, "template-index.html")
|
REDIRECT_TEMPLATE_PATH = os.path.join(TOOLS_PATH, "template-redirect.html")
|
||||||
TEMPLATE_PATH = os.path.join(TOOLS_PATH, "template.html")
|
TEMPLATE_PATH = os.path.join(TOOLS_PATH, "template.html")
|
||||||
FILTER_EXE = os.path.join(TOOLS_PATH, "filter.py")
|
FILTER_EXE = os.path.join(TOOLS_PATH, "filter.py")
|
||||||
POSTPROCESSOR_EXE = os.path.join(TOOLS_PATH, "postprocessor.py")
|
POSTPROCESSOR_EXE = os.path.join(TOOLS_PATH, "postprocessor.py")
|
||||||
|
@ -125,11 +128,6 @@ def run_git_fetch_and_restart_if_changed(remote_commits, target_branch):
|
||||||
os.execv(__file__, sys.argv)
|
os.execv(__file__, sys.argv)
|
||||||
|
|
||||||
|
|
||||||
def make_index_html(branch):
|
|
||||||
with open(TEMPLATE_INDEX_PATH) as f:
|
|
||||||
return f.read().format(branch=branch)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if os.environ.get("GITHUB_ACTIONS", "") == "true":
|
if os.environ.get("GITHUB_ACTIONS", "") == "true":
|
||||||
install_dependencies()
|
install_dependencies()
|
||||||
|
@ -152,17 +150,28 @@ def main():
|
||||||
run_git("rm", "--", path)
|
run_git("rm", "--", path)
|
||||||
branches, default_branch = sort_branches(branches)
|
branches, default_branch = sort_branches(branches)
|
||||||
branches_pretty = [pretty_branch_name(b) for b in branches]
|
branches_pretty = [pretty_branch_name(b) for b in branches]
|
||||||
default_branch_pretty = pretty_branch_name(default_branch)
|
|
||||||
for branch, src_path in branch_docs.items():
|
for branch, src_path in branch_docs.items():
|
||||||
branch_pretty = pretty_branch_name(branch)
|
branch_pretty = pretty_branch_name(branch)
|
||||||
to_path = "%s.html" % branch_pretty
|
to_path = "%s.html" % branch_pretty
|
||||||
convert_doc(src_path, to_path, branch_pretty, branches_pretty)
|
convert_doc(src_path, to_path, branch_pretty, branches_pretty)
|
||||||
run_git("add", "--", to_path)
|
run_git("add", "--", to_path)
|
||||||
if default_branch_pretty:
|
try:
|
||||||
index_path = "index.html"
|
with open(REDIRECT_CONFIG_PATH) as f:
|
||||||
with open(index_path, "w") as f:
|
redirect_config = json.load(f)
|
||||||
f.write(make_index_html(default_branch_pretty))
|
except FileNotFoundError:
|
||||||
run_git("add", "--", index_path)
|
redirect_config = {}
|
||||||
|
with open(REDIRECT_TEMPLATE_PATH) as f:
|
||||||
|
redirect_template = f.read()
|
||||||
|
for source, target in redirect_config.items():
|
||||||
|
if target == ":DEFAULT_BRANCH:":
|
||||||
|
if default_branch is None:
|
||||||
|
raise RuntimeError("no default branch")
|
||||||
|
target = pretty_branch_name(default_branch)
|
||||||
|
source_path = "%s.html" % str(source)
|
||||||
|
target_url = urllib.parse.quote("%s.html" % str(target))
|
||||||
|
with open(source_path, "w") as f:
|
||||||
|
f.write(redirect_template.format(target=target_url))
|
||||||
|
run_git("add", "--", source_path)
|
||||||
with contextlib.suppress(subprocess.CalledProcessError):
|
with contextlib.suppress(subprocess.CalledProcessError):
|
||||||
run_git("diff", "--cached", "--quiet")
|
run_git("diff", "--cached", "--quiet")
|
||||||
print("No changes", file=sys.stderr)
|
print("No changes", file=sys.stderr)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="Refresh" content="0; url={branch}.html">
|
<meta http-equiv="Refresh" content="0; url={target}">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link href="https://github.com/Kozea/Radicale/releases.atom" type="application/atom+xml" rel="alternate" title="Radicale Releases">
|
<link href="https://github.com/Kozea/Radicale/releases.atom" type="application/atom+xml" rel="alternate" title="Radicale Releases">
|
||||||
<title>Redirect</title>
|
<title>Redirect</title>
|
||||||
<p>Please follow <a href="{branch}.html">this link</a>.</p>
|
<p>Please follow <a href="{target}">this link</a>.</p>
|
3
redirect.json
Normal file
3
redirect.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"index": ":DEFAULT_BRANCH:"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue