Spaces:
Sleeping
Sleeping
| import os | |
| import glob | |
| pwa_tags = """ | |
| <!-- PWA Setup --> | |
| <link rel="manifest" href="/manifest.json"> | |
| <meta name="theme-color" content="#d4af37"> | |
| <link rel="apple-touch-icon" href="/static/images/hero2.jpg"> | |
| <script> | |
| if ('serviceWorker' in navigator) { | |
| window.addEventListener('load', () => { | |
| navigator.serviceWorker.register('/sw.js') | |
| .then(reg => console.log('ServiceWorker registered')) | |
| .catch(err => console.log('ServiceWorker registration failed: ', err)); | |
| }); | |
| } | |
| </script> | |
| </head> | |
| """ | |
| templates_dir = os.path.join(os.path.dirname(__file__), 'templates') | |
| for filepath in glob.glob(os.path.join(templates_dir, '*.html')): | |
| with open(filepath, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| # Only replace if not already added | |
| if "rel=\"manifest\"" not in content and "</head>" in content: | |
| content = content.replace("</head>", pwa_tags) | |
| with open(filepath, 'w', encoding='utf-8') as f: | |
| f.write(content) | |
| print(f"Patched {os.path.basename(filepath)}") | |