From 15e8cf9dcdb4b1cb88ab123238c802205710814b Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Thu, 13 Mar 2025 23:27:54 -0400 Subject: [PATCH] [+] Static page generation --- .gitignore | 1 + gen_static.py | 24 ++++++++++++++++++++++++ gentree.py | 4 ++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gen_static.py diff --git a/.gitignore b/.gitignore index e5150ae..0aaf949 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,4 @@ cython_debug/ .idea/ *.iml config.toml +public/index.html \ No newline at end of file diff --git a/gen_static.py b/gen_static.py new file mode 100644 index 0000000..3e649f9 --- /dev/null +++ b/gen_static.py @@ -0,0 +1,24 @@ +import shutil +from pathlib import Path + +from hypy_utils import write + +import bot +import db +import gentree + +src = Path(__file__).parent + +if __name__ == '__main__': + # Delete dist if already exists, and copy public to dist + shutil.rmtree(src / "dist", ignore_errors=True) + shutil.copytree(src / "public", src / "dist") + + # Pre-render all channel info + for channel in db.Channel.select(): + html = bot.channel_info(channel.username) + write(src / f"dist/c/{channel.username}.html", html) + + # Generate the full tree + gentree.gen_tree(src / "dist") + diff --git a/gentree.py b/gentree.py index 387d33b..9fc726a 100644 --- a/gentree.py +++ b/gentree.py @@ -27,9 +27,9 @@ def dfs(channel: str): return out -def gen_tree(): +def gen_tree(d: Path = src / "public"): of = dfs("hykilp") - write(src / "public/index.html", (src / "public/layout-full-tree.html").read_text() + write(d / "index.html", (src / "public/layout-full-tree.html").read_text() .replace("{{CONTENT}}", of))