Files
tonehaus/templates/base.html.twig
boris 1c98a634c3
All checks were successful
CI - Build Tonehaus Docker image / tonehaus-ci-build (push) Successful in 1m57s
eerrrrrr
2025-11-27 23:42:17 +00:00

47 lines
2.1 KiB
Twig

{% set accent_cookie = app.request.cookies.get('accentColor') %}
{% set accent_color = (accent_cookie is defined and accent_cookie and accent_cookie matches '/^#[0-9a-fA-F]{6}$/') ? accent_cookie : '#6750a4' %}
<!doctype html>
<html lang="en" data-bs-theme="{{ app.request.cookies.get('theme') ?? 'light' }}" style="--accent-color: {{ accent_color }};">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{% block title %}Music Ratings{% endblock %}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="stylesheet" href="{{ app.request.basePath }}/css/app.css">
<script>
(function() {
const root = document.documentElement;
const defaultAccent = '{{ accent_color|e('js') }}';
const match = document.cookie.match(/(?:^|; )accentColor=([^;]+)/);
const accent = match ? decodeURIComponent(match[1]) : defaultAccent;
function contrast(hex) {
const normalized = hex.replace('#', '');
if (normalized.length !== 6) {
return '#ffffff';
}
const r = parseInt(normalized.substring(0, 2), 16);
const g = parseInt(normalized.substring(2, 4), 16);
const b = parseInt(normalized.substring(4, 6), 16);
const luminance = (0.299 * r) + (0.587 * g) + (0.114 * b);
return luminance > 180 ? '#1c1b20' : '#ffffff';
}
root.style.setProperty('--accent-color', accent);
root.style.setProperty('--accent-on-color', contrast(accent));
})();
</script>
</head>
<body>
{% include '_partials/navbar.html.twig' %}
<main class="container py-4">
{% block body %}{% endblock %}
</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
{% include '_partials/auth_modal.html.twig' %}
</body>
</html>