import glob
import re

def sync_header():
    with open('index.html', 'r', encoding='utf-8') as f:
        index_content = f.read()

    # Extract the header block from index.html
    match = re.search(r'<!-- Franciscan Society - Responsive Menu Component -->[\s\S]*?<\/script>', index_content)
    if not match:
        print("Could not find the menu block in index.html")
        return
        
    menu_block = match.group(0)
    
    html_files = glob.glob('*.html')
    for file_path in html_files:
        if file_path == 'index.html':
            continue
            
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
            
        # Replace the header block
        new_content = re.sub(r'<!-- Franciscan Society - Responsive Menu Component -->[\s\S]*?<\/script>', menu_block, content)
        
        if new_content != content:
            with open(file_path, 'w', encoding='utf-8') as f:
                f.write(new_content)
            print(f"Updated {file_path}")

if __name__ == '__main__':
    sync_header()
