File size: 1,099 Bytes
5dbd6fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)}")