@@ -56,6 +56,46 @@ def build_toc_html(headings):
5656 return html
5757
5858
59+ def build_theme_css (theme_config ):
60+ """Build CSS variable overrides from theme config."""
61+ if not theme_config :
62+ return ""
63+
64+ # Map docs.yaml theme keys to CSS custom properties
65+ key_map = {
66+ "accent" : "--accent" ,
67+ "accent_dim" : "--accent-dim" ,
68+ "accent_glow" : "--accent-glow" ,
69+ "accent_glow_strong" : "--accent-glow-strong" ,
70+ "accent_warm" : "--accent-warm" ,
71+ "accent_warm_dim" : "--accent-warm-dim" ,
72+ "accent_red" : "--accent-red" ,
73+ "accent_blue" : "--accent-blue" ,
74+ "accent_purple" : "--accent-purple" ,
75+ "bg_deep" : "--bg-deep" ,
76+ "bg_surface" : "--bg-surface" ,
77+ "bg_raised" : "--bg-raised" ,
78+ "bg_hover" : "--bg-hover" ,
79+ "code_bg" : "--code-bg" ,
80+ "text" : "--text" ,
81+ "text_bright" : "--text-bright" ,
82+ "text_dim" : "--text-dim" ,
83+ "border" : "--border" ,
84+ "border_bright" : "--border-bright" ,
85+ }
86+
87+ overrides = []
88+ for yaml_key , css_var in key_map .items ():
89+ if yaml_key in theme_config :
90+ overrides .append (f" { css_var } : { theme_config [yaml_key ]} ;" )
91+
92+ if not overrides :
93+ return ""
94+
95+ lines = "\n " .join (overrides )
96+ return f"<style>\n :root {{\n { lines } \n }}\n </style>"
97+
98+
5999def render_page (template , config , page_content , nav_html , page_filename ):
60100 """Render a page by substituting variables into the template."""
61101 site = config ["site" ]
@@ -84,8 +124,12 @@ def render_page(template, config, page_content, nav_html, page_filename):
84124 f'</a>'
85125 )
86126
127+ # Theme overrides
128+ theme_css = build_theme_css (config .get ("theme" , {}))
129+
87130 # Substitutions
88131 output = template
132+ output = output .replace ("{{THEME_CSS}}" , theme_css )
89133 output = output .replace ("{{TITLE}}" , _escape (page_title ))
90134 output = output .replace ("{{SITE_TITLE}}" , _escape (site ["title" ]))
91135 output = output .replace ("{{TAGLINE}}" , _escape (site .get ("tagline" , "" )))
0 commit comments