1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-26 13:18:26 -04:00
jarv.is/pages/_document.tsx

45 lines
1.4 KiB
TypeScript

import { Html, Head, Main, NextScript } from "next/document";
import ThemeScript from "../components/ThemeScript/ThemeScript";
import { getCssText, reset, themeClassNames, themeStorageKey, preloadFonts } from "../lib/styles/stitches.config";
import * as config from "../lib/config";
// ensure the server can handle multiple requests without accumulating previous visitors' stylesheets
const getCssAndReset = () => {
const css = getCssText();
reset();
return css;
};
// https://nextjs.org/docs/advanced-features/custom-document
const Document = () => {
return (
<Html lang={config.siteLocale} className={themeClassNames["light"]}>
<Head>
{/* inject a small script to set/restore the user's theme ASAP */}
<ThemeScript {...{ themeClassNames, themeStorageKey }} />
{/* preload highest priority fonts defined in ../lib/styles/fonts/ */}
{preloadFonts.map((font) => (
<link
key={`font-${font.key}`}
rel="preload"
as="font"
type={font.type}
href={font.src}
crossOrigin="anonymous"
/>
))}
{/* stitches SSR: https://stitches.dev/blog/using-nextjs-with-stitches#step-3-ssr */}
<style id="stitches" dangerouslySetInnerHTML={{ __html: getCssAndReset() }} />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
};
export default Document;