mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
chore: Refactor build.py to use file context managers for reading and writing
This commit is contained in:
parent
52130ed6e8
commit
b599fdae47
1 changed files with 5 additions and 2 deletions
|
|
@ -100,13 +100,16 @@ def move_template(folder: Path, target_folder: Path):
|
|||
if "global-config" in file.parts or "jobs" in file.parts or "services" in file.parts:
|
||||
base_html = base_html.replace("data_server_builder[1:-1]", "data_server_builder")
|
||||
|
||||
content = file.read_text()
|
||||
with file.open("r") as f:
|
||||
content = f.read()
|
||||
|
||||
content = sub(r'(href|src)="\/(css|js|img|favicon|assets|js)\/[^<]*?(?=<|\/>)', format_template, content)
|
||||
# get the content before <body>
|
||||
content = content[: content.index("<body>")] + base_html
|
||||
|
||||
# write the new content
|
||||
file.write_text(content)
|
||||
with file.open("w") as f:
|
||||
f.write(content)
|
||||
|
||||
if target_folder.joinpath(f"{file.parent.name}.html").exists():
|
||||
target_folder.joinpath(f"{file.parent.name}.html").unlink()
|
||||
|
|
|
|||
Loading…
Reference in a new issue