feat: added copying static

This commit is contained in:
2025-04-10 13:56:28 +02:00
parent 3503d1d42f
commit 9e2ee75927
7 changed files with 131 additions and 9 deletions

41
stsg/build.py Normal file
View File

@@ -0,0 +1,41 @@
import logging
import shutil
from pathlib import Path
import os
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))
if not os.path.exists(src):
logger.warn("The static folder '%s' wasn't defined.", src)
return
logger.info("copying static files from '%s' to '%r'", src, dst)
os.makedirs(dst, exist_ok=True)
for root, dirs, files in os.walk(src):
# Compute relative path from the source root
rel_path = os.path.relpath(root, src)
dest_dir = os.path.join(dst, rel_path)
os.makedirs(dest_dir, exist_ok=True)
for file in files:
src_file = os.path.join(root, file)
dest_file = os.path.join(dest_dir, file)
shutil.copy2(src_file, dest_file)
print(src, dst)
def build():
logger.info("building static page")
copy_static()