1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-21 05:21:17 -04:00

set html class to light theme in static output

This commit is contained in:
2022-06-03 09:52:18 -04:00
parent acc6b11fa7
commit 3f931e01ce
8 changed files with 117 additions and 106 deletions

View File

@@ -1,9 +1,15 @@
import { useMemo } from "react";
import { minify } from "uglify-js";
import { clientScript } from "./client";
import { themeClassNames, themeStorageKey } from "../../lib/config/themes";
const ThemeScript = () => {
export type ThemeScriptProps = {
themeClassNames: {
[themeName: string]: string;
};
themeStorageKey: string;
};
const ThemeScript = ({ themeClassNames, themeStorageKey }: ThemeScriptProps) => {
const minified = useMemo(() => {
// since the client function will end up being injected as a plain dumb string, we need to set dynamic values here:
const functionString = String(clientScript)
@@ -30,7 +36,7 @@ const ThemeScript = () => {
}
return result.code;
}, []);
}, [themeClassNames, themeStorageKey]);
// the script tag injected manually into `<head>` in _document.tsx to prevent FARTing:
// https://css-tricks.com/flash-of-inaccurate-color-theme-fart/