move stylesheet variables to separate file and re-enable cache

This commit is contained in:
Izalia Mae 2024-03-04 15:29:08 -05:00
parent a0ee22406b
commit e86a376f6e
5 changed files with 22 additions and 22 deletions

View file

@ -263,11 +263,12 @@ async def handle_response_headers(request: web.Request, handler: Coroutine) -> R
resp = await handler(request) resp = await handler(request)
resp.headers['Server'] = 'ActivityRelay' resp.headers['Server'] = 'ActivityRelay'
# if not request.app['dev'] and request.path.endswith(('.css', '.js')): if not request.app['dev'] and request.path.endswith(('.css', '.js')):
# resp.headers['Cache-Control'] = 'public,max-age=2628000,immutable' # cache for 2 weeks
resp.headers['Cache-Control'] = 'public,max-age=1209600,immutable'
# else: else:
# resp.headers['Cache-Control'] = 'no-store' resp.headers['Cache-Control'] = 'no-store'
return resp return resp

View file

@ -11,6 +11,7 @@
%title << {{config.name}}: {{page}} %title << {{config.name}}: {{page}}
%meta(charset="UTF-8") %meta(charset="UTF-8")
%meta(name="viewport" content="width=device-width, initial-scale=1") %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") %link(rel="stylesheet" type="text/css" href="/style.css")
-block head -block head

View file

@ -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 { a {
color: var(--primary); color: var(--primary);
text-decoration: none; text-decoration: none;

View file

@ -44,7 +44,7 @@ class Template(Environment):
'domain': self.app.config.domain, 'domain': self.app.config.domain,
'version': __version__, 'version': __version__,
'config': config, 'config': config,
'theme': THEMES.get(config['theme'], THEMES['default']), 'theme_name': config['theme'] or 'Default',
**(context or {}) **(context or {})
} }

View file

@ -445,3 +445,18 @@ class StyleCss(View):
async def get(self, request: Request) -> Response: async def get(self, request: Request) -> Response:
data = self.template.render('style.css', self) data = self.template.render('style.css', self)
return Response.new(data, ctype = 'css') 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')