Skip to content

Commit

Permalink
docs: setup twostash (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Aug 6, 2024
1 parent 85d746c commit 14adf89
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 15 deletions.
1 change: 1 addition & 0 deletions apps/docs/app/docs/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DocsLayout } from "fumadocs-ui/layout";
import type { ReactNode } from "react";
import { docsOptions } from "./layout.config";
import "fumadocs-ui/twoslash.css";

export default function Layout({ children }: { children: ReactNode }) {
return <DocsLayout {...docsOptions}>{children}</DocsLayout>;
Expand Down
7 changes: 4 additions & 3 deletions apps/docs/content/docs/runtimes/custom-rest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ Update the `MyModelAdapter` below to integrate with your own custom API.

`@/app/MyRuntimeProvider.tsx`

```tsx
```tsx twoslash
"use client";

import type { ReactNode } from "react";
import {
AssistantRuntimeProvider,
useLocalRuntime,
Expand Down Expand Up @@ -77,7 +78,7 @@ const MyModelAdapter: ChatModelAdapter = {
export function MyRuntimeProvider({
children,
}: Readonly<{
children: React.ReactNode;
children: ReactNode;
}>) {
const runtime = useLocalRuntime(MyModelAdapter);

Expand Down Expand Up @@ -144,4 +145,4 @@ const MyModelAdapter: ChatModelAdapter = {
}
},
};
```
```
29 changes: 27 additions & 2 deletions apps/docs/mdx-components.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import type { MDXComponents } from 'mdx/types';
import defaultComponents from 'fumadocs-ui/mdx';
import type { MDXComponents } from "mdx/types";
import { Accordion, Accordions } from "fumadocs-ui/components/accordion";
import { Callout } from "fumadocs-ui/components/callout";
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
import { TypeTable } from "fumadocs-ui/components/type-table";
import defaultComponents from "fumadocs-ui/mdx";
import {
CodeBlock,
type CodeBlockProps,
Pre,
} from "fumadocs-ui/components/codeblock";
import { Popup, PopupContent, PopupTrigger } from "fumadocs-ui/twoslash/popup";

export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...defaultComponents,
Popup,
PopupContent,
PopupTrigger,
pre: (props: CodeBlockProps) => (
<CodeBlock {...props}>
<Pre className="max-h-[400px]">{props.children}</Pre>
</CodeBlock>
),
Tabs,
Tab,
Callout,
TypeTable,
Accordion,
Accordions,
blockquote: (props) => <Callout>{props.children}</Callout>,
...components,
};
}
19 changes: 18 additions & 1 deletion apps/docs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import createMDX from "fumadocs-mdx/config";
import { rehypeCodeDefaultOptions } from "fumadocs-core/mdx-plugins";
import { transformerTwoslash } from "fumadocs-twoslash";

const withMDX = createMDX();
const withMDX = createMDX({
mdxOptions: {
rehypeCodeOptions: {
transformers: [
...rehypeCodeDefaultOptions.transformers,
transformerTwoslash({
twoslashOptions: {
compilerOptions: {
jsx: 12,
},
},
}),
],
},
},
});

/** @type {import('next').NextConfig} */
const config = {
Expand Down
1 change: 1 addition & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"clsx": "^2.1.1",
"fumadocs-core": "13.0.7",
"fumadocs-mdx": "9.0.0",
"fumadocs-twoslash": "^1.1.1",
"fumadocs-ui": "13.0.7",
"geist": "^1.3.1",
"lucide-react": "^0.424.0",
Expand Down
77 changes: 68 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 14adf89

Please sign in to comment.