import os import yaml import shutil from jinja2 import Environment, FileSystemLoader DATA_DIR = 'data' TEMPLATE_DIR = 'templates' STATIC_DIR = 'static' OUTPUT_DIR = 'public' def load_profiles(): profiles = [] for filename in os.listdir(DATA_DIR): if filename.endswith('.yaml') or filename.endswith('.yml'): with open(os.path.join(DATA_DIR, filename), 'r') as f: profile = yaml.safe_load(f) profiles.append(profile) return profiles def build(): # 1. Prepare Output Directory if os.path.exists(OUTPUT_DIR): shutil.rmtree(OUTPUT_DIR) os.makedirs(OUTPUT_DIR) # 2. Load Data profiles = load_profiles() # 3. Setup Jinja2 env = Environment(loader=FileSystemLoader(TEMPLATE_DIR)) template = env.get_template('index.html.j2') # 4. Render Template output_html = template.render(profiles=profiles) with open(os.path.join(OUTPUT_DIR, 'index.html'), 'w') as f: f.write(output_html) # 5. Copy Static Assets shutil.copytree(STATIC_DIR, os.path.join(OUTPUT_DIR, 'static')) print(f"✅ Build complete! Output in '{OUTPUT_DIR}'") if __name__ == "__main__": build()