import os

# 获取当前目录下所有图片后缀的文件
exts = ['.html','.py']
images = [f for f in os.listdir('.') if os.path.splitext(f)[1].lower() in exts]

# 生成 HTML 内容
html_content = f"""
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>本地图片预览</title>
    <style>
        body {{ display: flex; flex-wrap: wrap; gap: 10px; background: #222; }}
        img {{ width: 200px; height: 200px; object-fit: cover; border-radius: 8px; }}
    </style>
</head>
<body>
    {''.join([f'<img src="{img}">' for img in images])}
</body>
</html>
"""

with open("index.html", "w", encoding="utf-8") as f:
    f.write(html_content)
