Apply palettes to shared layouts and template pages

This commit is contained in:
2026-11-28 12:37:25 +08:00
parent 1aaf3908af
commit 70a94dd394
15 changed files with 104 additions and 27 deletions
+11 -3
View File
@@ -187,7 +187,7 @@ final class DesignController extends AdminController
return (new SiteController())->renderPage($repo, $page, true);
}
public function palette(Request $request, string $id): Response
public function palette(Request $request, string $id, string $scope = ''): Response
{
$palette = DesignLibrary::find((int) $id, 'palette');
if (!$palette) {
@@ -197,11 +197,19 @@ final class DesignController extends AdminController
foreach ($palette['payload'] as $variable => $value) {
$declarations[] = '--' . $variable . ':' . $value;
}
$variables = implode(';', $declarations);
if ($scope === 'region') {
$region = ':is([data-site-area], main)[data-region-palette="' . $palette['id'] . '"]';
$css = "$region {" . $variables . ';color:var(--ink);background-color:var(--white)}'
. " $region .site-footer {--paper:inherit;--ink:inherit;--muted:inherit;background-color:var(--paper)}";
} else {
$css = ':root, #main-content.page-theme {' . $variables . '}'
. ' #main-content:not(.page-theme) .hero-home {background:var(--paper)}';
}
return new Response(200, [
'Content-Type' => 'text/css; charset=utf-8', 'Cache-Control' => 'public, max-age=60',
'X-Content-Type-Options' => 'nosniff',
], ':root, #main-content.page-theme {' . implode(';', $declarations) . '} .page-theme .hero, .hero-home {background:var(--paper)}'
. ' #main-content .button-primary, #main-content .button-primary:hover {color:var(--button-ink);background:var(--accent)}');
], $css);
}
}