From 911b7e9270bb37af519c5db076934af74c19d273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Tue, 18 Jun 2024 14:03:53 +0200 Subject: [PATCH] Fixup to #8: handle relative paths --- book/update-theme.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/book/update-theme.py b/book/update-theme.py index deda8181..76ca50e9 100755 --- a/book/update-theme.py +++ b/book/update-theme.py @@ -5,6 +5,8 @@ from contextlib import closing from http.client import HTTPSConnection from io import StringIO from json import load +from os import PathLike +from pathlib import Path INDEX_HBS_DOMAIN = "api.github.com" @@ -49,7 +51,7 @@ SIDEBAR_END = r""" """ -def main(): +def update_theme(target: PathLike) -> None: with closing(HTTPSConnection(INDEX_HBS_DOMAIN, INDEX_HBS_PORT)) as conn: conn.request(INDEX_HBS_PROTO, INDEX_HBS_PATH, None, INDEX_HBS_HEADERS) res = conn.getresponse() @@ -64,7 +66,7 @@ def main(): output_f = StringIO() _, revision = data["git_url"].rsplit("/", 1) - print("{{!-- Source revision:", revision, "--}}", file=output_f) + print("Source revision:", revision) state = "before-sidebar" for line in input_f: @@ -93,10 +95,13 @@ def main(): state = "after-sidebar" output_f.write(line) + if state != "after-sidebar": + raise Exception(f"state={state!r}") + output_f.seek(0, 0) - with open("./theme/index.hbs", "wt") as f: + with open(target, "wt") as f: print(output_f.read(), end="", file=f) if __name__ == "__main__": - main() + update_theme(Path(__file__).absolute().parent / "theme" / "index.hbs")