From 22c1dd04c2fd57b06aa70b555c6d75cbe60381f6 Mon Sep 17 00:00:00 2001 From: Valerio Ageno <51341197+Valerioageno@users.noreply.github.com> Date: Thu, 6 Feb 2025 20:58:33 +0100 Subject: [PATCH] docs: enable posthog analytics (#519) --- apps/documentation/.env.local | 4 + apps/documentation/.env.production | 4 + apps/documentation/package.json | 1 + apps/documentation/src/components/App/App.tsx | 118 ++++++++++++++++++ .../documentation/src/components/App/index.ts | 3 + .../components/PostHog/PostHogPageView.tsx | 20 +++ .../components/PostHog/PostHogProvider.tsx | 31 +++++ .../src/components/PostHog/index.ts | 4 + apps/documentation/src/env.d.ts | 10 ++ apps/documentation/src/routes/__layout.tsx | 116 ++--------------- pnpm-lock.yaml | 33 +++++ 11 files changed, 236 insertions(+), 108 deletions(-) create mode 100644 apps/documentation/.env.local create mode 100644 apps/documentation/.env.production create mode 100644 apps/documentation/src/components/App/App.tsx create mode 100644 apps/documentation/src/components/App/index.ts create mode 100644 apps/documentation/src/components/PostHog/PostHogPageView.tsx create mode 100644 apps/documentation/src/components/PostHog/PostHogProvider.tsx create mode 100644 apps/documentation/src/components/PostHog/index.ts create mode 100644 apps/documentation/src/env.d.ts diff --git a/apps/documentation/.env.local b/apps/documentation/.env.local new file mode 100644 index 00000000..d144ca46 --- /dev/null +++ b/apps/documentation/.env.local @@ -0,0 +1,4 @@ +VITE_PUBLIC_POSTHOG_KEY=phc_wqyze0qQlWutAwL5RL1Bv83D8bdySCkhcFw9MkTVuI8 +VITE_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com +VITE_ENV=development +VITE_ENABLE_POSTHOG=false diff --git a/apps/documentation/.env.production b/apps/documentation/.env.production new file mode 100644 index 00000000..306fd390 --- /dev/null +++ b/apps/documentation/.env.production @@ -0,0 +1,4 @@ +VITE_PUBLIC_POSTHOG_KEY=phc_wqyze0qQlWutAwL5RL1Bv83D8bdySCkhcFw9MkTVuI8 +VITE_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com +VITE_ENV=production +VITE_ENABLE_POSTHOG=true diff --git a/apps/documentation/package.json b/apps/documentation/package.json index 3470aacf..5075fd34 100644 --- a/apps/documentation/package.json +++ b/apps/documentation/package.json @@ -17,6 +17,7 @@ "@mdx-js/react": "3.1.0", "@tabler/icons-react": "3.28.1", "clsx": "2.1.1", + "posthog-js": "^1.215.5", "react": "19.0.0", "react-dom": "19.0.0", "remark-gfm": "4.0.0", diff --git a/apps/documentation/src/components/App/App.tsx b/apps/documentation/src/components/App/App.tsx new file mode 100644 index 00000000..ec42ed2e --- /dev/null +++ b/apps/documentation/src/components/App/App.tsx @@ -0,0 +1,118 @@ +import type { ReactNode, JSX } from 'react' + +import { createTheme, MantineProvider, AppShell } from '@mantine/core' + +import type { CSSVariablesResolver } from '@mantine/core' +import { useDisclosure } from '@mantine/hooks' + +import PageWithTOC from '@/components/PageWithTOC' +import Navbar from '@/components/Navbar' +import Sidebar from '@/components/Sidebar' +import MdxProvider from '@/components/MdxProvider' + +import '@mantine/core/styles.css' +import '@mantine/code-highlight/styles.css' +import Footer from '@/components/Footer' + +interface RootRouteProps { + children: ReactNode +} + +const theme = createTheme({ + primaryColor: 'violet', + primaryShade: { light: 6, dark: 9 }, + fontFamily: 'Inter', + fontFamilyMonospace: 'Menlo', + respectReducedMotion: true, + radius: { + xs: '4px', + sm: '4px', + lg: '8px', + xl: '8px', + md: '8px', + }, + fontSizes: { + // 'xs' | 'sm' | 'md' | 'lg' | 'xl' + xs: '14px', + sm: '14px', + }, + colors: { + dark: [ + '#d5d7e0', + '#acaebf', + '#8c8fa3', + '#666980', + '#4d4f66', + '#34354a', + '#2b2c3d', + '#1d1e30', + '#0c0d21', + '#01010a', + ], + }, + headings: { + sizes: { + h1: { + fontSize: '48px', + }, + }, + }, + other: { + sidebarGrayLight: '#495057', + sidebarGrayDark: '#adb5bd', + sidebarTextHoverLight: '#212529', + sidebarTextHoverDark: '#f8f9fa', + }, +}) + +const resolver: CSSVariablesResolver = (th) => { + const { + sidebarGrayLight, + sidebarTextHoverLight, + sidebarGrayDark, + sidebarTextHoverDark, + } = th.other as Record + + return { + variables: {}, + light: { + '--mantine-color-footer-bg': th.colors.gray[1], + '--mantine-color-sidebar-gray': sidebarGrayLight, + '--mantine-color-sidebar-text-hover': sidebarTextHoverLight, + '--mantine-color-quote-border': th.colors.violet[1], + }, + dark: { + '--mantine-color-footer-bg': th.colors.dark[6], + '--mantine-color-sidebar-gray': sidebarGrayDark, + '--mantine-color-sidebar-text-hover': sidebarTextHoverDark, + '--mantine-color-quote-border': th.colors.violet[9], + }, + } +} + +export default function App({ children }: RootRouteProps): JSX.Element { + const [opened, { toggle }] = useDisclosure() + + return ( + + + + + + + {children} + + +