import os
import glob
import re

blog_dir = "/Users/Ediz/Desktop/kamilweb/tostum/blog"
blog_files = glob.glob(os.path.join(blog_dir, "*.html"))

for file_path in blog_files:
    with open(file_path, "r", encoding="utf-8") as f:
        content = f.read()
    
    # Replace external images with placeholder images
    content = re.sub(r'<img\s+src="https?://[^"]+"\s*(.*?)>', r'<img src="../images/dismekan.jpg" \1>', content)
    
    # Ensure article tags are present around the main content
    if "<article>" not in content and file_path.endswith("index.html") == False:
        # Just simple semantic wrapping for blog posts
        content = re.sub(r'<section class="container[^"]*"(.*?)>', r'<main class="container"\1><article>', content)
        content = re.sub(r'</section>', r'</article></main>', content)
        
    with open(file_path, "w", encoding="utf-8") as f:
        f.write(content)

print("Blog files processed.")
