"""One-time developer script: break V3 full themes into independently maintainable Jinja page templates.""" from pathlib import Path import re base=Path(__file__).resolve().parent.parent/'themes' types={'home':['home'],'search':['search'],'listing':['listing','category'],'product':['product'], 'brand':['brand'],'article':['article'],'case':['case'],'info':['about','service','contact','faq','standard'],'notfound':['notfound']} markers=[("{% if kind=='home' %}",'home'),("{% elif kind=='search' %}",'search'),("{% elif kind in ['listing','category'] %}",'listing'),("{% elif kind=='product' %}",'product'),("{% elif kind=='brand' %}",'brand'),("{% elif kind=='article' %}",'article'),("{% elif kind=='case' %}",'case'),("{% elif kind in ('about','service','contact','faq','standard') %}",'info'),("{% elif kind=='notfound' %}",'notfound')] for name in ('automotive','industrial','corporate','minimal'): p=base/name/'pro.html' t=p.read_text(encoding='utf-8') beginning=t.index(markers[0][0]); ending=t.index('{% endif %}\n{% if has_custom',beginning) common=t[:beginning] remainder=t[ending+len('{% endif %}'):] # preserve custom blocks and footer dir=base/name/'pages';dir.mkdir(parents=True,exist_ok=True) pieces={} for i,(marker,key) in enumerate(markers): start=t.index(marker,beginning)+len(marker) finish=t.index(markers[i+1][0],start) if i+1