diff --git a/app/src/hooks.server.ts b/app/src/hooks.server.ts index b01aa8c..70ab421 100644 --- a/app/src/hooks.server.ts +++ b/app/src/hooks.server.ts @@ -1,4 +1,5 @@ import type { Handle } from '@sveltejs/kit'; +import { themes } from '$lib/themes' import { i18n } from '$lib/i18n'; import { validateSessionToken, setSessionTokenCookie, deleteSessionTokenCookie } from "$lib/server/session"; import { sequence } from "@sveltejs/kit/hooks"; @@ -29,4 +30,18 @@ const authHandle: Handle = async ({ event, resolve }) => { return resolve(event); }; -export const handle: Handle = sequence(handleParaglide, authHandle); \ No newline at end of file +const themeHandler: Handle = async ({ event, resolve }) => { + const theme = event.cookies.get('theme') + + if (!theme || !themes.includes(theme)) { + return await resolve(event) + } + + return await resolve(event, { + transformPageChunk: ({ html }) => { + return html.replace('data-theme=""', `data-theme="${theme}"`) + }, + }) +} + +export const handle: Handle = sequence(handleParaglide, authHandle,themeHandler); \ No newline at end of file diff --git a/app/src/lib/theme-select.svelte b/app/src/lib/theme-select.svelte new file mode 100644 index 0000000..3d36b52 --- /dev/null +++ b/app/src/lib/theme-select.svelte @@ -0,0 +1,58 @@ + + +