diff --git a/relay/application.py b/relay/application.py index f3d9810..dfa3861 100644 --- a/relay/application.py +++ b/relay/application.py @@ -263,11 +263,12 @@ async def handle_response_headers(request: web.Request, handler: Coroutine) -> R resp = await handler(request) resp.headers['Server'] = 'ActivityRelay' -# if not request.app['dev'] and request.path.endswith(('.css', '.js')): -# resp.headers['Cache-Control'] = 'public,max-age=2628000,immutable' + if not request.app['dev'] and request.path.endswith(('.css', '.js')): + # cache for 2 weeks + resp.headers['Cache-Control'] = 'public,max-age=1209600,immutable' -# else: -# resp.headers['Cache-Control'] = 'no-store' + else: + resp.headers['Cache-Control'] = 'no-store' return resp diff --git a/relay/frontend/base.haml b/relay/frontend/base.haml index c74feda..e1da33c 100644 --- a/relay/frontend/base.haml +++ b/relay/frontend/base.haml @@ -11,6 +11,7 @@ %title << {{config.name}}: {{page}} %meta(charset="UTF-8") %meta(name="viewport" content="width=device-width, initial-scale=1") + %link(rel="stylesheet" type="text/css" href="/theme/{{theme_name}}.css") %link(rel="stylesheet" type="text/css" href="/style.css") -block head diff --git a/relay/frontend/style.css b/relay/frontend/style.css index d258640..47b0f3a 100644 --- a/relay/frontend/style.css +++ b/relay/frontend/style.css @@ -1,20 +1,3 @@ -:root { - --text: {{theme["text"]}}; - --background: {{theme["background"]}}; - --primary: {{theme["primary"]}}; - --primary-hover: {{theme["primary-hover"]}}; - --section-background: {{theme["section-background"]}}; - --table-background: {{theme["table-background"]}}; - --border: {{theme["border"]}}; - --message-text: {{theme["message-text"]}}; - --message-background: {{theme["message-background"]}}; - --message-border: {{theme["message-border"]}}; - --error-text: {{theme["error-text"]}}; - --error-background: {{theme["error-background"]}}; - --error-border: {{theme["error-border"]}}; - --spacing: 10px; -} - a { color: var(--primary); text-decoration: none; diff --git a/relay/template.py b/relay/template.py index 9f3a09b..64738e0 100644 --- a/relay/template.py +++ b/relay/template.py @@ -44,7 +44,7 @@ class Template(Environment): 'domain': self.app.config.domain, 'version': __version__, 'config': config, - 'theme': THEMES.get(config['theme'], THEMES['default']), + 'theme_name': config['theme'] or 'Default', **(context or {}) } diff --git a/relay/views/frontend.py b/relay/views/frontend.py index 9df5e45..bd63417 100644 --- a/relay/views/frontend.py +++ b/relay/views/frontend.py @@ -445,3 +445,18 @@ class StyleCss(View): async def get(self, request: Request) -> Response: data = self.template.render('style.css', self) return Response.new(data, ctype = 'css') + + +@register_route('/theme/{theme}.css') +class ThemeCss(View): + async def get(self, request: Request, theme: str) -> Response: + try: + context = { + 'theme': THEMES[theme] + } + + except KeyError: + return Response.new('Invalid theme', 404) + + data = self.template.render('variables.css', self, **context) + return Response.new(data, ctype = 'css')