import Document, { Html, Head, Main, NextScript, DocumentContext } from "next/document";
import { ServerStyleSheet } from "styled-components";
const MyDocument = (props) => {
// 从 props 中获取语言信息,如果没有则默认为 zh-CN
const locale = props.locale || "zh-CN";
return (
NSGM CLI
{/* 直接使用现有的 FontAwesome CSS 文件 */}
{/* 预加载字体文件以改善性能 */}
{/* 确保字体正确显示的额外样式 */}
{/* 抑制服务端渲染的 useLayoutEffect 警告 */}
);
};
// MyDocument.renderDocument = Document.renderDocument
MyDocument.getInitialProps = async (ctx: DocumentContext) => {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;
try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) => sheet.collectStyles(),
});
const initialProps = await Document?.getInitialProps(ctx);
return {
...initialProps,
locale: ctx.locale || "zh-CN",
styles: [initialProps.styles, sheet.getStyleElement()],
};
} finally {
sheet.seal();
}
};
export default MyDocument;