|
| 1 | +import os |
| 2 | +import glob |
| 3 | +import re |
| 4 | +from PIL import Image, ImageDraw |
| 5 | + |
| 6 | +base_dir = r'c:\Users\PMLS\Desktop\Youtube Shorts\b2b_blog' |
| 7 | +icons_dir = os.path.join(base_dir, 'assets', 'icons') |
| 8 | +os.makedirs(icons_dir, exist_ok=True) |
| 9 | + |
| 10 | +size = 192 |
| 11 | +img = Image.new('RGBA', (size, size), (0,0,0,0)) |
| 12 | +draw = ImageDraw.Draw(img) |
| 13 | + |
| 14 | +# Dark sleek background |
| 15 | +draw.rounded_rectangle([(0,0), (size-1, size-1)], radius=40, fill=(15, 23, 42, 255)) |
| 16 | + |
| 17 | +# Sharp tech 'T' logo in TechStack Blue |
| 18 | +draw.rectangle([(50, 60), (142, 85)], fill=(56, 189, 248, 255)) # Top bar |
| 19 | +draw.rectangle([(84, 85), (108, 140)], fill=(56, 189, 248, 255)) # Stem |
| 20 | + |
| 21 | +# Save files |
| 22 | +img.save(os.path.join(icons_dir, 'techstack-logo-192.png')) |
| 23 | + |
| 24 | +img_32 = img.resize((32, 32), Image.Resampling.LANCZOS) |
| 25 | +img_32.save(os.path.join(icons_dir, 'favicon-32.png')) |
| 26 | + |
| 27 | +img_16 = img.resize((16, 16), Image.Resampling.LANCZOS) |
| 28 | +img_16.save(os.path.join(icons_dir, 'favicon-16.png')) |
| 29 | + |
| 30 | +img_32.save(os.path.join(icons_dir, 'favicon.ico'), format='ICO', sizes=[(16, 16), (32, 32)]) |
| 31 | + |
| 32 | +svg = '''<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 192"> |
| 33 | + <rect width="192" height="192" rx="40" fill="#0f172a"/> |
| 34 | + <path d="M 50 60 L 142 60 L 142 85 L 108 85 L 108 140 L 84 140 L 84 85 L 50 85 Z" fill="#38bdf8"/> |
| 35 | +</svg>''' |
| 36 | +with open(os.path.join(icons_dir, 'techstack-logo.svg'), 'w') as f: |
| 37 | + f.write(svg) |
| 38 | + |
| 39 | +print('Icons generated.') |
| 40 | + |
| 41 | +html_files = glob.glob(os.path.join(base_dir, '*.html')) + glob.glob(os.path.join(base_dir, 'posts', '*.html')) |
| 42 | + |
| 43 | +new_tags = ''' <link rel="icon" type="image/png" sizes="32x32" href="/assets/icons/favicon-32.png"> |
| 44 | + <link rel="icon" type="image/png" sizes="16x16" href="/assets/icons/favicon-16.png"> |
| 45 | + <link rel="apple-touch-icon" sizes="192x192" href="/assets/icons/techstack-logo-192.png"> |
| 46 | + <link rel="shortcut icon" href="/assets/icons/favicon.ico">''' |
| 47 | + |
| 48 | +for fpath in html_files: |
| 49 | + with open(fpath, 'r', encoding='utf-8') as f: |
| 50 | + content = f.read() |
| 51 | + |
| 52 | + # Strip existing favicon tags |
| 53 | + content = re.sub(r'<link[^>]+rel=[\'"](?:shortcut )?icon[\'"][^>]*>', '', content, flags=re.IGNORECASE) |
| 54 | + content = re.sub(r'<link[^>]+rel=[\'"]apple-touch-icon[\'"][^>]*>', '', content, flags=re.IGNORECASE) |
| 55 | + |
| 56 | + # Clean up empty lines left behind by re.sub |
| 57 | + content = re.sub(r'\n\s*\n\s*</head>', '\n</head>', content) |
| 58 | + |
| 59 | + # Insert new tags |
| 60 | + content = content.replace('</head>', f'{new_tags}\n</head>') |
| 61 | + |
| 62 | + with open(fpath, 'w', encoding='utf-8') as f: |
| 63 | + f.write(content) |
| 64 | + |
| 65 | +print('HTML headers updated.') |
0 commit comments