import glob
import re

def fix_blog_and_menu():
    html_files = glob.glob('*.html')
    
    for file_path in html_files:
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
            
        new_content = content
        
        # 1. Remove the "Overview" submenu items from Ministries and Community
        # They look like:
        # <h3>Ministries</h3>
        # <a href="ministries.html">Overview</a>
        # Let's just remove the exact string:
        new_content = re.sub(r'<h3>Ministries</h3>\s*<a href="ministries\.html">Overview</a>', '<h3>Ministries</h3>', new_content, flags=re.IGNORECASE)
        new_content = re.sub(r'<h3>Community</h3>\s*<a href="community\.html">Overview</a>', '<h3>Community</h3>', new_content, flags=re.IGNORECASE)

        # 2. For blog-detail files, replace the article body with placeholder text
        if file_path.startswith('blog-detail-') and file_path.endswith('.html'):
            placeholder_html = """<div class="article-content" id="article-body">
                <p>Welcome to our blog. This is a placeholder post where we will soon share reflections, stories, and insights about our ongoing journey. Please check back later for more detailed updates.</p>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
                <h2>Continuing the Path</h2>
                <p>Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
            </div>"""
            
            # Find the article body and replace it
            new_content = re.sub(
                r'<div class="article-content" id="article-body">.*?</div>\s*<div class="article-footer">',
                f'{placeholder_html}\n\n            <div class="article-footer">',
                new_content,
                flags=re.DOTALL
            )
            
            # Also change the category to BLOG
            new_content = re.sub(
                r'<span class="article-category">.*?</span>',
                '<span class="article-category">BLOG</span>',
                new_content,
                flags=re.DOTALL
            )
            
        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__':
    fix_blog_and_menu()
