"""Compress the finished static and variable TTFs for the web.""" from pathlib import Path from fontTools.ttLib import TTFont ROOT = Path(__file__).resolve().parent.parent def main(): source = ROOT / 'build/TTF' output = ROOT / 'build/WOFF2' output.mkdir(parents=True, exist_ok=True) for path in sorted(source.glob('*.ttf')): destination = output / path.with_suffix('.woff2').name with TTFont(path, recalcTimestamp=False) as font: font.flavor = 'woff2' font.save(destination) print(f'Compressed {path.name} → {destination.relative_to(ROOT)}') if __name__ == '__main__': main()