@writely/preview
Version:
Lightning-fast development server with live preview for Writely blogs. Hot reload, file watching, and instant feedback for the best development experience.
41 lines (40 loc) • 1.48 kB
JSX
import "@writely/core/globals.css";
import { ThemeEnum, getTheme } from "@writely/core";
import { Inter } from "next/font/google";
import React from "react";
import Script from "next/script";
const inter = Inter({ subsets: ["latin"] });
export default function RootLayout({ children, config }) {
// Validate theme and provide fallback
const validatedTheme = ThemeEnum.safeParse(config.theme).success
? config.theme
: "nova";
const ThemeComponent = getTheme(validatedTheme);
// Create properly typed config
const themeConfig = {
...config,
theme: validatedTheme,
};
return (<html lang="en" suppressHydrationWarning>
<head>
<Script id="live-reload" strategy="beforeInteractive" dangerouslySetInnerHTML={{
__html: `
(function() {
const socket = new WebSocket('ws://localhost:${process.env.PORT || 3000}');
socket.addEventListener('message', function (event) {
if (event.data === 'reload') {
window.location.reload();
}
});
socket.addEventListener('error', function (event) {
console.log('WebSocket error:', event);
});
})();
`,
}}/>
</head>
<body className={inter.className}>
<ThemeComponent config={themeConfig}>{children}</ThemeComponent>
</body>
</html>);
}