Apply site.cfg_json theme defaults only on first-run (no persisted ae_loc); preserve manual/URL overrides

This commit is contained in:
Scott Idem
2026-04-08 16:07:20 -04:00
parent 8aef519aa6
commit 534bda9203

View File

@@ -393,12 +393,21 @@ export async function load({ fetch, params, parent, route, url }) {
ae_loc_init['site_google_tracking_id'] = json_data.google_tracking_id || '';
ae_loc_init['site_access_code_kv'] = json_data.access_code_kv_json || {};
ae_loc_init['site_cfg_json'] = json_data.cfg_json || {};
// If the site-level cfg_json provides a theme, apply it as a default
// so the site admin can select a preferred theme via site.cfg_json.
// This will later be overridable by a URL `?theme=` param or user/local setting.
// Apply site-level theme defaults only when there is no persisted ae_loc
// in localStorage (first-run). URL params and manual selection still override.
try {
const scfg = ae_loc_init['site_cfg_json'] as any;
if (scfg && typeof scfg === 'object') {
let has_persisted_ae_loc = false;
if (typeof localStorage !== 'undefined') {
try {
const raw = localStorage.getItem('ae_loc');
if (raw) has_persisted_ae_loc = true;
} catch (e) {
has_persisted_ae_loc = false;
}
}
if (scfg && typeof scfg === 'object' && !has_persisted_ae_loc) {
if (scfg.theme_name) ae_loc_init['theme_name'] = scfg.theme_name;
if (scfg.theme_mode && (scfg.theme_mode === 'light' || scfg.theme_mode === 'dark'))
ae_loc_init['theme_mode'] = scfg.theme_mode;