Theme key 'theme', storage keys in the cookie scanner, type in the cookie list
- Theme choice in localStorage under 'theme' (next-themes' key and values)
instead of 'ipal-theme'. ThemeScript moves an old choice before the first
paint and removes the old key; useTheme / ThemeSwitcher do the same
without the script. ipalKit({ theme: { storageKey } }) sets an own key,
which reaches ThemeScript through getSiteShell().theme and <html
data-theme-storage>.
- The cookie scanner declares the theme key (Theme choice: local storage,
necessary, until changed or site data is cleared) when the theme switch
is on, so Scan cookies finds it without a crawl.
- Cookies -> Cookie list rows get a Type (cookie / local storage / session
storage, default cookie, shared by every language), filled by scan, review
and approval. The detailed settings window and <CookieTable> show it with
English and Polish defaults; the approval page marks storage entries.
- Migration: adds cookie_settings_cookies.storage (DEFAULT 'cookie') and
cookie_settings_locales.detail_labels_storage, nothing else.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6998b44431
commit
b5368cdc61
@@ -4,6 +4,7 @@ import type { CookieDeclaration, CookieIntegration, CookieScanContext } from './
|
||||
import { adminTexts } from '../../admin-i18n/texts/index.js'
|
||||
import { validAnalyticsId } from '../../analytics/idFormats.js'
|
||||
import { LOCALE_COOKIE_NAME } from '../../i18n/negotiateLocale.js'
|
||||
import { THEME_STORAGE_KEY } from '../../theme/theme.js'
|
||||
import { getTurnstileConfig } from '../../turnstile/config.js'
|
||||
import { CONSENT_COOKIE } from '../storage.js'
|
||||
import { textFor } from './merge.js'
|
||||
@@ -19,6 +20,17 @@ const months = (n: number) => T(`${n} months`, `${n} mies.`)
|
||||
const YEAR = T('1 year', '1 rok')
|
||||
const TWO_YEARS = T('2 years', '2 lata')
|
||||
const SITE = 'This site'
|
||||
const UNTIL_CHANGED = T('Until changed or site data is cleared', 'Do zmiany lub wyczyszczenia danych witryny')
|
||||
|
||||
/** Site Settings → Theme → visitors may switch: only then is the choice stored. */
|
||||
async function themeToggleOn(ctx: CookieScanContext): Promise<boolean> {
|
||||
try {
|
||||
const settings = (await ctx.payload.findGlobal({ slug: 'site-settings' as never, depth: 0 })) as { allowThemeToggle?: boolean }
|
||||
return settings.allowThemeToggle === true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
/** A name from the shared admin texts, in every admin language the plugin ships. */
|
||||
const A = (key: AdminTextKey) => ({ en: adminTexts.en[key], pl: adminTexts.pl[key] })
|
||||
|
||||
@@ -47,6 +59,24 @@ export const DEFAULT_COOKIE_INTEGRATIONS: CookieIntegration[] = [
|
||||
key: 'consent',
|
||||
label: A('cookieIntegrationConsent'),
|
||||
},
|
||||
{
|
||||
// Browser storage, not a cookie: the light / dark choice the visitor made themselves —
|
||||
// a preference they asked for, so necessary (no separate consent); editable in review.
|
||||
declarations: (ctx) => [
|
||||
{
|
||||
name: ctx.plugin.themeStorageKey || THEME_STORAGE_KEY,
|
||||
category: 'necessary',
|
||||
purpose: T('Remembers the light or dark theme you chose.', 'Zapamiętuje wybrany motyw: jasny lub ciemny.'),
|
||||
retention: UNTIL_CHANGED,
|
||||
setBeforeConsent: true,
|
||||
storage: 'localStorage',
|
||||
vendor: SITE,
|
||||
},
|
||||
],
|
||||
isEnabled: themeToggleOn,
|
||||
key: 'theme',
|
||||
label: A('cookieIntegrationTheme'),
|
||||
},
|
||||
{
|
||||
declarations: (ctx) => [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user