fresh
fresh copied to clipboard
feat: apply `lang` and `bodyClass` set in middleware to template
Hi again! As followup to #47, setting ctx.lang doesn't appear to do anything as ServerContext is isolated from RenderContext. These changes enable a middleware to apply a lang param (e.g. based on Accept-Language header) that will be rendered in the server-side template (as <html lang={lang}>).
Additionally, I added a bodyClass param that has similar behavior, but instead sets a class on the <body> tag. This enables a middleware to apply the correct theme during SSR via the Sec-CH-Prefers-Color-Scheme client-hint header. This also resolves #473.
This implementation piggybacks on the existing params object, though these values could be passed via a separate method. Let me know what you think!