#!/usr/bin/env python3 """ 修復所有 HTML 文件的導航列,移除重複項目 """ import os import re from pathlib import Path # 標準導航列模板 STANDARD_NAVBAR = '''
''' # 頁面 active 標記映射 PAGE_ACTIVE_MAP = { 'dashboard.html': {'active_dashboard': ' active'}, 'edm_dashboard.html': {'active_edm': ' {% if current_promo_page in [\'edm\', \'festival\'] %}active{% endif %}'}, 'sales_analysis.html': {'active_analysis': ' active'}, 'daily_sales.html': {'active_analysis': ' active'}, 'vendor_stockout_index.html': {'active_vendor': ' active'}, 'vendor_stockout_list.html': {'active_vendor': ' active'}, 'vendor_stockout_import.html': {'active_vendor': ' active'}, 'vendor_stockout_send_email.html': {'active_vendor': ' active'}, 'vendor_stockout_history.html': {'active_vendor': ' active'}, 'auto_import_index.html': {'active_import': ' active'}, 'settings.html': {'active_system': ' active'}, 'system_settings.html': {'active_system': ' active'}, 'logs.html': {'active_system': ' active'}, 'growth_analysis.html': {}, } def fix_navbar(file_path): """修復單個 HTML 文件的導航列""" with open(file_path, 'r', encoding='utf-8') as f: content = f.read() # 檢查是否有導航列 if '\s*' replacement = navbar + '\n \n ' new_content = re.sub(pattern, replacement, content, flags=re.DOTALL) if new_content == content: print(f"⚠️ {file_path.name} 替換失敗") return False # 寫回文件 with open(file_path, 'w', encoding='utf-8') as f: f.write(new_content) print(f"✅ 已修復 {file_path.name}") return True def main(): """主程序""" base_dir = Path(__file__).parent html_files = list(base_dir.glob('*.html')) print(f"找到 {len(html_files)} 個 HTML 文件") print("=" * 50) fixed_count = 0 for file_path in sorted(html_files): if fix_navbar(file_path): fixed_count += 1 print("=" * 50) print(f"\n✅ 完成!修復了 {fixed_count} 個文件") if __name__ == "__main__": main()