import os
import glob
import re

files = glob.glob('e:/project/escort promotion/frontend/admin/*.html')

pattern = r'(<li><a href="pages\.html"[^>]*><i class="fa-solid fa-file-alt"></i>\s*Pages\s*</a></li>)'
replacement = r'\1\n      <li><a href="sitemap.html"><i class="fa-solid fa-sitemap"></i> Sitemap</a></li>'

for f in files:
    if f.endswith('sitemap.html'):
        continue
    with open(f, 'r', encoding='utf-8') as file:
        content = file.read()
    
    # Check if already added
    if 'href="sitemap.html"' in content:
        continue
        
    orig = content
    content = re.sub(pattern, replacement, content, flags=re.IGNORECASE)
    
    if content != orig:
        with open(f, 'w', encoding='utf-8') as file:
            file.write(content)
        print(f"Updated {f}")

print("Done updating admin UI sidebar!")
