diff --git a/client/components/playground/scripts.tsx b/client/components/playground/scripts.tsx deleted file mode 100644 index d07b1ac..0000000 --- a/client/components/playground/scripts.tsx +++ /dev/null @@ -1,23 +0,0 @@ -export interface PlaygroundScriptsProps { - code: string; - autoplay?: boolean; -} - -export default function PlaygroundScripts(props: PlaygroundScriptsProps) { - return ( -
`, - }} - > -
- ); -} - -function initializeData(props: PlaygroundScriptsProps) { - return ``; -} diff --git a/client/nav.tsx b/client/nav.tsx deleted file mode 100644 index 7afc393..0000000 --- a/client/nav.tsx +++ /dev/null @@ -1,28 +0,0 @@ -export default function Nav() { - return ( - - ); -} diff --git a/client/playgrounds.ts b/client/playgrounds.ts deleted file mode 100644 index 2db0a0a..0000000 --- a/client/playgrounds.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Playground is a jsonx playground. - */ -export interface Playground { - id: string; - version: string; - code: string; -} - -/** - * AddPlaygroundRequest is the request to add a playground. - */ -export type AddPlaygroundRequest = Omit; diff --git a/components/doc/doc.tsx b/components/doc/doc.tsx new file mode 100644 index 0000000..5910c67 --- /dev/null +++ b/components/doc/doc.tsx @@ -0,0 +1,37 @@ +import { contents } from "#/lib/resources/docs.ts"; +import { fromExpression } from "#/lib/playgrounds/expressions/mod.ts"; +import { getMeta } from "#/lib/meta/mod.ts"; +import { toPath } from "#/lib/to_path.ts"; +import type { DocContentProps } from "./doc_content.tsx"; +import DocContent from "./doc_content.tsx"; + +export default async function DocumentationPage(request: Request) { + const content = contentOf(request); + const playground = await playgroundOf(content.playground); + return ( + + ); +} + +function contentOf(request: Request) { + const url = new URL(request.url); + const path = toPath(url.pathname).join("/"); + const content = contents.get(path); + if (!content) { + throw new Error(`Content not found: ${path}`); + } + + return content; +} + +async function playgroundOf(expression?: string) { + let playground: DocContentProps["playground"]; + if (expression) { + playground = { + data: await fromExpression(expression), + meta: await getMeta(), + }; + } + + return playground; +} diff --git a/components/doc/doc_content.tsx b/components/doc/doc_content.tsx new file mode 100644 index 0000000..e1ef9be --- /dev/null +++ b/components/doc/doc_content.tsx @@ -0,0 +1,63 @@ +import type { PlaygroundData } from "#/lib/playgrounds/mod.ts"; +import { Meta } from "#/lib/meta/mod.ts"; +import Playground from "#/components/playground/playground.tsx"; +import { Head } from "$fresh/runtime.ts"; +import Hljs from "#/components/hljs.tsx"; + +/** + * DocContentProps are the properties for the DocContent component. + */ +export interface DocContentProps { + /** + * body is the html content of the documentation page. + */ + body: string; + + /** + * toc is the table of contents of the documentation page. + */ + toc?: string; + + /** + * playground is the playground data for the documentation page. + */ + playground?: { + data: PlaygroundData; + meta: Meta; + }; +} + +/** + * DocContent is the content of a jsonx documentation page. + */ +export default function DocContent(props: DocContentProps) { + return ( + <> + + + + + + + + +
+
+
+ {props.playground && ( + + )} +
+ + ); +} diff --git a/components/foot.tsx b/components/foot.tsx new file mode 100644 index 0000000..bc52d66 --- /dev/null +++ b/components/foot.tsx @@ -0,0 +1,19 @@ +/** + * Foot is the site footer. + */ +export default function Foot( + props: { year?: number } = { year: new Date().getFullYear() }, +) { + return ( + + ); +} diff --git a/components/hljs.tsx b/components/hljs.tsx new file mode 100644 index 0000000..c4411b3 --- /dev/null +++ b/components/hljs.tsx @@ -0,0 +1,13 @@ +/** + * Hljs is a component that loads the highlight.js styles. + */ +export default function Hljs(props: { id: string }) { + return ( + <> + + + ); +} diff --git a/components/nav.tsx b/components/nav.tsx new file mode 100644 index 0000000..85b2aab --- /dev/null +++ b/components/nav.tsx @@ -0,0 +1,43 @@ +import ToC from "#/components/toc.tsx"; +import { nodes } from "#/lib/resources/docs.ts"; + +/** + * NavProps are the properties for the Nav component. + */ +export interface NavProps { + path: string[]; +} + +/** + * Nav is the navigation bar for the documentation. + */ +export default function Nav(props: NavProps) { + return ( + + ); +} + +function startsWith(path: string[], prefix: string[]): boolean { + if (path.length < prefix.length) { + return false; + } + + for (let i = 0; i < prefix.length; i++) { + if (path[i] !== prefix[i]) { + return false; + } + } + + return true; +} diff --git a/client/components/playground/playground.tsx b/components/playground/playground.tsx similarity index 93% rename from client/components/playground/playground.tsx rename to components/playground/playground.tsx index 4f595a3..6a84991 100644 --- a/client/components/playground/playground.tsx +++ b/components/playground/playground.tsx @@ -1,4 +1,5 @@ -import type { Meta } from "#/client/meta.ts"; +import { Head } from "$fresh/runtime.ts"; +import type { Meta } from "#/lib/meta/mod.ts"; import PlaygroundScripts from "./scripts.tsx"; export interface PlaygroundProps { @@ -11,6 +12,9 @@ export interface PlaygroundProps { export default function Playground(props: PlaygroundProps) { return ( <> + + +
diff --git a/components/playground/scripts.tsx b/components/playground/scripts.tsx new file mode 100644 index 0000000..861c433 --- /dev/null +++ b/components/playground/scripts.tsx @@ -0,0 +1,22 @@ +export interface PlaygroundScriptsProps { + code: string; + autoplay?: boolean; +} + +export default function PlaygroundScripts(props: PlaygroundScriptsProps) { + return ( + <> + +