#!/usr/bin/env python3 """ Applicera förenklad infographic på alla branschsidor. Användning: python3 apply-simple-infographic.py [--dry-run] """ import argparse from pathlib import Path def apply_infographic(industry_dir, dry_run=False): """Applicera infographic på en branschsida.""" html_file = industry_dir / 'index.html' if not html_file.exists(): return False, "index.html saknas" # Läs befintlig HTML content = html_file.read_text(encoding='utf-8') # Kolla om redan har infographic if 'qi-infographic' in content: return False, "Har redan infographic" # Läs infographic-komponent infographic_path = industry_dir.parent / '_components' / 'infographic-industry-simple.html' if not infographic_path.exists(): return False, f"Komponent saknas: {infographic_path}" infographic = infographic_path.read_text(encoding='utf-8') if dry_run: return True, "Skulle applicera" # Injicera före body_end = content.rfind('') if body_end == -1: return False, "Ingen hittad" injection = f'''
{infographic}
''' new_content = content[:body_end] + injection + '\n' + content[body_end:] html_file.write_text(new_content, encoding='utf-8') return True, "Applicerad" def main(): parser = argparse.ArgumentParser() parser.add_argument('--dry-run', action='store_true') args = parser.parse_args() root = Path(__file__).parent.parent / 'se' print("=== Applicera förenklad infographic ===\n") count = 0 for subdir in sorted(root.iterdir()): if not subdir.is_dir(): continue if subdir.name.startswith('_'): continue if not (subdir / 'index.html').exists(): continue success, msg = apply_infographic(subdir, dry_run=args.dry_run) status = "✅" if success else "⚠️" print(f" {status} {subdir.name}: {msg}") if success: count += 1 print(f"\n=== {count} sidor uppdaterade ===") if __name__ == '__main__': main()