import type { Data } from "@/pages/docs/+data"; import { snippetsService } from "@/services/SnippetsService"; import { Highlight, Prism } from "prism-react-renderer"; import { clientOnly } from "vike-react/clientOnly"; import { prismThemes } from "@/data/themes/prism"; import { useData } from "vike-react/useData"; import { useTheme } from "@/hooks/useTheme"; import { Fragment, useMemo } from "react"; const CSRSnippet = clientOnly(() => import("./CSRSnippet")); function SSRSnippet({ language, children }: { language: string; children: string }) { const { theme } = useTheme(); const prismTheme = useMemo(() => { return prismThemes[theme]; }, [theme]); return ( {({ className, style, tokens, getTokenProps }) => (
          
            {tokens.map((line, lineIndex) => (
              
                {line
                  .filter((token) => !token.empty)
                  .map((token, tokenIndex) => (
                    
                  ))}
                {"\n"}
              
            ))}
          
        
)}
); } export function Snippet({ path, language, label }: { path: string; language: string; label?: string }) { const { snippets } = useData(); const snippet = snippets.find((snippet) => snippet.path === path); if (!snippet || !snippet.content) return null; const props = { language, label, children: snippet.content, }; return (
} />
); }