|
| 1 | +"""Make switcher.json to allow docs to switch between different versions.""" |
| 2 | + |
1 | 3 | import json |
2 | 4 | import logging |
3 | 5 | from argparse import ArgumentParser |
|
6 | 8 |
|
7 | 9 |
|
8 | 10 | def report_output(stdout: bytes, label: str) -> list[str]: |
| 11 | + """Print and return something received frm stdout.""" |
9 | 12 | ret = stdout.decode().strip().split("\n") |
10 | 13 | print(f"{label}: {ret}") |
11 | 14 | return ret |
@@ -52,21 +55,20 @@ def get_versions(ref: str, add: str | None) -> list[str]: |
52 | 55 | return versions |
53 | 56 |
|
54 | 57 |
|
55 | | -def write_json(path: Path, repository: str, versions: str): |
| 58 | +def write_json(path: Path, repository: str, versions: list[str]): |
| 59 | + """Write the JSON switcher to path.""" |
56 | 60 | org, repo_name = repository.split("/") |
57 | | - pages_url = f"https://{org}.github.io" |
58 | | - if repo_name != f"{org}.github.io": |
59 | | - # Only add the repo name if it isn't the source for the org pages site |
60 | | - pages_url += f"/{repo_name}" |
61 | 61 | struct = [ |
62 | | - {"version": version, "url": f"{pages_url}/{version}/"} for version in versions |
| 62 | + {"version": version, "url": f"https://{org}.github.io/{repo_name}/{version}/"} |
| 63 | + for version in versions |
63 | 64 | ] |
64 | 65 | text = json.dumps(struct, indent=2) |
65 | 66 | print(f"JSON switcher:\n{text}") |
66 | 67 | path.write_text(text, encoding="utf-8") |
67 | 68 |
|
68 | 69 |
|
69 | 70 | def main(args=None): |
| 71 | + """Parse args and write switcher.""" |
70 | 72 | parser = ArgumentParser( |
71 | 73 | description="Make a versions.json file from gh-pages directories" |
72 | 74 | ) |
|
0 commit comments