diff --git a/src/components/mdx/Grid.tsx b/src/components/mdx/Grid.tsx new file mode 100644 index 00000000..f0dfe91e --- /dev/null +++ b/src/components/mdx/Grid.tsx @@ -0,0 +1,16 @@ +export const Grid = ({ children, cols = 4 }: { children: React.ReactNode; cols?: number }) => ( + +) diff --git a/src/components/mdx/Hint.tsx b/src/components/mdx/Hint.tsx new file mode 100644 index 00000000..2aa9de9c --- /dev/null +++ b/src/components/mdx/Hint.tsx @@ -0,0 +1,7 @@ +export const Hint = ({ children }: { children: React.ReactNode }) => { + return ( +
+ {children} +
+ ) +} diff --git a/src/components/mdx/index.tsx b/src/components/mdx/index.tsx new file mode 100644 index 00000000..5e83273f --- /dev/null +++ b/src/components/mdx/index.tsx @@ -0,0 +1,96 @@ +import { MARKDOWN_REGEX } from '@/utils/docs' + +export * from './Grid' +export * from './Hint' + +export const h2 = ({ children, id }: { children: React.ReactNode; id: string }) => ( + +

{children}

+
+) +const h3 = ({ children, id }: { children: React.ReactNode; id: string }) => ( + +

{children}

+
+) +const h4 = ({ children, id }: { children: React.ReactNode; id: string }) => ( + +

{children}

+
+) + +const ul = ({ children }: { children: React.ReactNode }) => ( + +) +const ol = ({ children }: { children: React.ReactNode }) => ( +
    {children}
+) +const li = ({ children }: { children: React.ReactNode }) => ( +
  • {children}
  • +) + +const p = ({ children }: { children: React.ReactNode }) => ( +

    {children}

    +) + +const blockquote = ({ children }: { children: React.ReactNode }) => ( +
    {children}
    +) + +const table = ({ children }: { children: React.ReactNode }) => ( +
    +
    +
    +
    + {children}
    +
    +
    +
    +
    +) + +const a = ({ + href, + target, + rel, + children, +}: { + href: string + target?: string + rel?: string + children: React.ReactNode +}) => { + const isAnchor = href.startsWith('https://') + target = isAnchor ? '_blank' : target + rel = isAnchor ? 'noopener noreferrer' : rel + href = isAnchor ? href : href.replace(MARKDOWN_REGEX, '') + return ( + + {children} + + ) +} + +export const img = ({ + src, + alt, + width, + height, + ...rest +}: { + src: string + alt: string + width: number + height: number +}) => ( + // eslint-disable-next-line @next/next/no-img-element + {alt} +) diff --git a/src/utils/docs.tsx b/src/utils/docs.tsx index 9a881623..0b922e83 100644 --- a/src/utils/docs.tsx +++ b/src/utils/docs.tsx @@ -12,6 +12,8 @@ import rehypePrismPlus from 'rehype-prism-plus' import { codesandbox, toc } from '@/utils/rehype' import Codesandbox, { fetchCSB } from '@/components/Codesandbox' +import * as components from '@/components/mdx' + /** * Checks for .md(x) file extension */ @@ -52,114 +54,6 @@ async function crawl(dir: string, filter?: RegExp, files: string[] = []) { * @param root - absolute or relative (to cwd) path to docs folder */ -const components = { - Codesandbox, - Hint: ({ children }: { children: React.ReactNode }) => ( -
    - {children} -
    - ), - Grid: ({ children, cols = 4 }: { children: React.ReactNode; cols?: number }) => ( - - ), - h2: ({ children, id }: { children: React.ReactNode; id: string }) => ( - -

    {children}

    -
    - ), - h3: ({ children, id }: { children: React.ReactNode; id: string }) => ( - -

    {children}

    -
    - ), - h4: ({ children, id }: { children: React.ReactNode; id: string }) => ( - -

    {children}

    -
    - ), - ul: ({ children }: { children: React.ReactNode }) => , - ol: ({ children }: { children: React.ReactNode }) =>
      {children}
    , - li: ({ children }: { children: React.ReactNode }) => ( -
  • {children}
  • - ), - p: ({ children }: { children: React.ReactNode }) => ( -

    {children}

    - ), - blockquote: ({ children }: { children: React.ReactNode }) => ( -
    {children}
    - ), - table: ({ children }: { children: React.ReactNode }) => ( -
    -
    -
    -
    - - {children} -
    -
    -
    -
    -
    - ), - a: ({ - href, - target, - rel, - children, - }: { - href: string - target?: string - rel?: string - children: React.ReactNode - }) => { - const isAnchor = href.startsWith('https://') - target = isAnchor ? '_blank' : target - rel = isAnchor ? 'noopener noreferrer' : rel - href = isAnchor ? href : href.replace(MARKDOWN_REGEX, '') - return ( - - {children} - - ) - }, - img: ({ - src, - alt, - width, - height, - ...rest - }: { - src: string - alt: string - width: number - height: number - }) => ( - // eslint-disable-next-line @next/next/no-img-element - {alt} - ), -} - async function _getDocs( root: string, slugOfInterest: string[] | null, diff --git a/tailwind.config.ts b/tailwind.config.ts index 65090444..44b2db9f 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -2,11 +2,7 @@ import type { Config } from 'tailwindcss' const config: Config = { darkMode: 'class', - content: [ - './src/pages/**/*.{js,ts,jsx,tsx,mdx}', - './src/components/**/*.{js,ts,jsx,tsx,mdx}', - './src/app/**/*.{js,ts,jsx,tsx,mdx}', - ], + content: ['./src/components/**/*.{js,ts,jsx,tsx,mdx}', './src/app/**/*.{js,ts,jsx,tsx,mdx}'], plugins: [require('@tailwindcss/typography'), require('@tailwindcss/aspect-ratio')], } export default config