From b28bb334127a29ffc4c5175b902fb2e642e3f47e Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 10 Apr 2025 15:58:01 +0200 Subject: [PATCH] feat: added recursively copying static files --- stsg/build.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/stsg/build.py b/stsg/build.py index 83809e2..90fd0fa 100644 --- a/stsg/build.py +++ b/stsg/build.py @@ -9,10 +9,7 @@ from .config import SOURCE_DIRECTORY, DIST_DIRECTORY, STATIC_DIRECTORY logger = logging.getLogger("stsg.build") -def copy_static(): - src = str(Path(SOURCE_DIRECTORY, STATIC_DIRECTORY)) - dst = str(Path(DIST_DIRECTORY, STATIC_DIRECTORY)) - +def copy_static(src, dst): if not os.path.exists(src): logger.warn("The static folder '%s' wasn't defined.", src) return @@ -30,7 +27,7 @@ def copy_static(): dest_dir = os.path.join(dst, rel_path) os.makedirs(dest_dir, exist_ok=True) - + for file in files: if file.startswith("."): continue @@ -67,9 +64,30 @@ class Context: return text +def walk_directory(root): + src_path = Path(SOURCE_DIRECTORY, root) + dst_path = Path(DIST_DIRECTORY, root) + + for current_full_path in src_path.iterdir(): + current_name = Path(current_full_path).name + current_dst = Path(dst_path, current_name) + current_src = Path(src_path, current_name) + + if current_name == "static": + print(current_src, current_dst) + copy_static(current_src, current_dst) + continue + + if current_dst.is_dir(): + walk_directory(Path(root, current_full_path.name)) + + def build(): logger.info("building static page") - copy_static() + + walk_directory("") + return + # copy_static() context = Context()