From 7e433d619420615df79e74fba102d8eea8effc28 Mon Sep 17 00:00:00 2001
From: martabal <74269598+martabal@users.noreply.github.com>
Date: Thu, 24 Oct 2024 10:18:00 +0200
Subject: [PATCH] fix: script in app.html
---
web/src/app.html | 31 +------------------
web/src/hooks.server.ts | 12 ++++++-
.../onboarding-page/onboarding-theme.svelte | 2 +-
.../shared-components/immich-logo.svelte | 2 +-
.../shared-components/map/map.svelte | 2 +-
.../shared-components/theme-button.svelte | 2 +-
web/src/lib/constants.ts | 6 ----
web/src/lib/stores/preferences.store.ts | 11 ++-----
web/src/lib/utils.ts | 8 +++++
web/src/lib/utils/fouc.ts | 12 +++++++
web/src/lib/utils/theme.ts | 11 +++++++
web/src/routes/+layout.svelte | 6 ++--
12 files changed, 52 insertions(+), 53 deletions(-)
create mode 100644 web/src/lib/utils/fouc.ts
create mode 100644 web/src/lib/utils/theme.ts
diff --git a/web/src/app.html b/web/src/app.html
index 6fd02dc9f8..677891592e 100644
--- a/web/src/app.html
+++ b/web/src/app.html
@@ -66,37 +66,8 @@
background-color: black;
}
-
+ %app.fouc%
diff --git a/web/src/hooks.server.ts b/web/src/hooks.server.ts
index 1606f92796..9f8d22cd98 100644
--- a/web/src/hooks.server.ts
+++ b/web/src/hooks.server.ts
@@ -1,12 +1,22 @@
import overpass from '$lib/assets/fonts/overpass/Overpass.ttf?url';
import overpassMono from '$lib/assets/fonts/overpass/OverpassMono.ttf?url';
+import { transpileFile } from '$lib/utils';
+import fouc from '$lib/utils/fouc?raw';
+import theme from '$lib/utils/theme?raw';
import type { Handle } from '@sveltejs/kit';
// only used during the build to replace the variables from app.html
export const handle = (async ({ event, resolve }) => {
return resolve(event, {
transformPageChunk: ({ html }) => {
- return html.replace('%app.font%', overpass).replace('%app.monofont%', overpassMono);
+ const themePrepared = theme.replaceAll(/^export\s+/gm, '');
+ const foucPrepared = fouc.replaceAll(/^import.*$/gm, themePrepared);
+ const scriptFouc = ``;
+
+ return html
+ .replace('%app.font%', overpass)
+ .replace('%app.monofont%', overpassMono)
+ .replace('%app.fouc%', scriptFouc);
},
});
}) satisfies Handle;
diff --git a/web/src/lib/components/onboarding-page/onboarding-theme.svelte b/web/src/lib/components/onboarding-page/onboarding-theme.svelte
index 975dbd1ec3..f16f9b8be2 100644
--- a/web/src/lib/components/onboarding-page/onboarding-theme.svelte
+++ b/web/src/lib/components/onboarding-page/onboarding-theme.svelte
@@ -5,7 +5,7 @@
import OnboardingCard from './onboarding-card.svelte';
import { colorTheme } from '$lib/stores/preferences.store';
import { moonPath, moonViewBox, sunPath, sunViewBox } from '$lib/assets/svg-paths';
- import { Theme } from '$lib/constants';
+ import { Theme } from '$lib/utils/theme';
import { t } from 'svelte-i18n';
export let onDone: () => void;
diff --git a/web/src/lib/components/shared-components/immich-logo.svelte b/web/src/lib/components/shared-components/immich-logo.svelte
index 952960ef3f..cb77f40ca0 100644
--- a/web/src/lib/components/shared-components/immich-logo.svelte
+++ b/web/src/lib/components/shared-components/immich-logo.svelte
@@ -3,7 +3,7 @@
import logoLightUrl from '$lib/assets/immich-logo-inline-light.svg';
import logoNoText from '$lib/assets/immich-logo.svg';
import { content as alternativeLogo } from '$lib/assets/immich-logo.json';
- import { Theme } from '$lib/constants';
+ import { Theme } from '$lib/utils/theme';
import { colorTheme } from '$lib/stores/preferences.store';
import { DateTime } from 'luxon';
import type { HTMLImgAttributes } from 'svelte/elements';
diff --git a/web/src/lib/components/shared-components/map/map.svelte b/web/src/lib/components/shared-components/map/map.svelte
index 60d7f0e755..036da41e1e 100644
--- a/web/src/lib/components/shared-components/map/map.svelte
+++ b/web/src/lib/components/shared-components/map/map.svelte
@@ -4,9 +4,9 @@