parse styles.css to set PWA theme color

Hunter
Thursday, November 6th, 2025 at 12:44 AM

generate_manifests.py+30-2

generate_manifests.py
 5  """
 6  
 7  import json
 8 +import re
 9  from pathlib import Path
10  
11  SCRIPT_DIR = Path(__file__).parent.absolute()
12  TRACKS_JSON = SCRIPT_DIR / "tracks.json"
13 +STYLES_CSS = SCRIPT_DIR / "styles.css"
14 +
15 +
16 +def get_background_color():
17 +	"""Extract the --background CSS variable from styles.css"""
18 +	if not STYLES_CSS.exists():
19 +		print("Warning: styles.css not found. Using default color.")
20 +		return "#080a0c"
21 +
22 +	with open(STYLES_CSS, 'r', encoding='utf-8') as f:
23 +		content = f.read()
24 +
25 +	# Look for --background: <color>; pattern
26 +	match = re.search(
27 +		r'--background:\s*([#a-zA-Z0-9(),.\s]+?)\s*;',
28 +		content
29 +	)
30 +	if match:
31 +		color = match.group(1).strip()
32 +		print(f"Found background color in styles.css: {color}")
33 +		return color
34 +
35 +	print("Warning: --background not found in styles.css. Using default color.")
36 +	return "#080a0c"
37  
38  
39  def generate_pwa_manifests():

48  	with open(TRACKS_JSON, 'r', encoding='utf-8') as f:
49  		tracks = json.load(f)
50  
51 +	# Get background color from styles.css
52 +	background_color = get_background_color()
53 +
54  	# Generate manifest.json
55  	manifest = {
56  		"id": "/vibe_capsule/",

60  		"start_url": "/vibe_capsule/",
61  		"scope": "/vibe_capsule/",
62  		"display": "standalone",
   -		"background_color": "#080a0c",
   -		"theme_color": "#080a0c",
63 +		"background_color": background_color,
64 +		"theme_color": background_color,
65  		"icons": [
66  			{
67  				"src": "resources/icon.png",