Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render markdown as documentation pages #6

Merged
merged 35 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
16de4e7
add overview docs content
EthanThatOneKid Mar 19, 2024
da50e4e
toc wip
EthanThatOneKid Mar 20, 2024
e5778fe
move nav to components dir
EthanThatOneKid Mar 20, 2024
d1e131b
wip
EthanThatOneKid Mar 20, 2024
91de5da
wip
EthanThatOneKid Mar 21, 2024
604073b
wip
EthanThatOneKid Mar 21, 2024
555031e
wip
EthanThatOneKid Mar 21, 2024
c8544aa
wip
EthanThatOneKid Mar 21, 2024
957f2e9
wip
EthanThatOneKid Mar 22, 2024
50b24b1
wip
EthanThatOneKid Mar 22, 2024
3ccc606
wip
EthanThatOneKid Mar 22, 2024
526d250
Merge branch 'fix/5' of https://github.com/FartLabs/jsonx_docs into f…
EthanThatOneKid Mar 22, 2024
5f69bcd
file `server/docs/docs.ts` is coming together
EthanThatOneKid Mar 22, 2024
1c298b9
abstract global styles to static file `global.css`
EthanThatOneKid Mar 22, 2024
cb27a2b
add `toPath`
EthanThatOneKid Mar 23, 2024
dd09995
add `components\doc\expression.ts`
EthanThatOneKid Mar 23, 2024
a9893df
Update deno.jsonc
EthanThatOneKid Mar 23, 2024
3ed5cd0
wip
EthanThatOneKid Mar 24, 2024
b81905a
drawer wip
EthanThatOneKid Mar 24, 2024
5b7501f
add playground to doc component
EthanThatOneKid Mar 25, 2024
168fd70
import shared code in 2 route files
EthanThatOneKid Mar 25, 2024
ad33e1d
Delete drawer.tsx
EthanThatOneKid Mar 25, 2024
ebeb00d
navigation looks good!
EthanThatOneKid Mar 25, 2024
beee124
add alias `p` for route `playgrounds`
EthanThatOneKid Mar 25, 2024
901e721
add footer (w/ css grid)
EthanThatOneKid Mar 26, 2024
f09d782
replace gfm with markdown-it
EthanThatOneKid Mar 26, 2024
a20df34
Update fs.ts
EthanThatOneKid Mar 26, 2024
81d7436
fix toc component
EthanThatOneKid Mar 26, 2024
ed584d2
fix hljs
EthanThatOneKid Mar 26, 2024
6e0fd4b
use markdown-it toc in cousin element
EthanThatOneKid Mar 26, 2024
859cecb
add 'copy code to clipboard' button to code blocks
EthanThatOneKid Mar 27, 2024
0433f48
Create 00_index.md
EthanThatOneKid Mar 27, 2024
05b8fca
wip
EthanThatOneKid Mar 27, 2024
18020d5
wip
EthanThatOneKid Mar 27, 2024
ef56f80
update documentation
EthanThatOneKid Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions client/components/playground/scripts.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions client/nav.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions client/playgrounds.ts

This file was deleted.

37 changes: 37 additions & 0 deletions components/doc/doc.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<DocContent body={content.body} toc={content.toc} playground={playground} />
);
}

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;
}
63 changes: 63 additions & 0 deletions components/doc/doc_content.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<Head>
<Hljs id="github" />
<script src="/copy.js" defer></script>
<link rel="stylesheet" href="/md.css" />
</Head>

<aside class="aside">
<h2>On this page</h2>
<div dangerouslySetInnerHTML={{ __html: props.toc ?? "" }}></div>
</aside>

<main class="main">
<div
className="markdown-body"
dangerouslySetInnerHTML={{ __html: props.body }}
>
</div>
{props.playground && (
<Playground
code={props.playground.data.code}
version={props.playground.data.version}
meta={props.playground.meta}
/>
)}
</main>
</>
);
}
19 changes: 19 additions & 0 deletions components/foot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Foot is the site footer.
*/
export default function Foot(
props: { year?: number } = { year: new Date().getFullYear() },
) {
return (
<footer class="foot">
<hr />
<p>
© {props.year}{" "}
<a href="https://github.com/FartLabs">
<strong>@FartLabs</strong>
</a>{" "}
🧪
</p>
</footer>
);
}
13 changes: 13 additions & 0 deletions components/hljs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Hljs is a component that loads the highlight.js styles.
*/
export default function Hljs(props: { id: string }) {
return (
<>
<link
rel="stylesheet"
href={`https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/${props.id}.min.css`}
/>
</>
);
}
43 changes: 43 additions & 0 deletions components/nav.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<nav class="nav">
<a href="/">
<h1>jsonx</h1>
</a>

<ToC
nodes={nodes}
filter={(node) =>
startsWith(props.path, node.name) &&
node.name.length <= props.path.length + 1}
/>
</nav>
);
}

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;
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -11,6 +12,9 @@ export interface PlaygroundProps {
export default function Playground(props: PlaygroundProps) {
return (
<>
<Head>
<link rel="stylesheet" href="/playground.css" />
</Head>
<PlaygroundScripts autoplay={props.autoplay ?? true} code={props.code} />
<details id="codeDetails" open>
<summary>
Expand Down
22 changes: 22 additions & 0 deletions components/playground/scripts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export interface PlaygroundScriptsProps {
code: string;
autoplay?: boolean;
}

export default function PlaygroundScripts(props: PlaygroundScriptsProps) {
return (
<>
<script
id="initialJSONData"
type="application/json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(props) }}
>
</script>
<script
type="module"
src="/script.js"
defer
/>
</>
);
}
25 changes: 25 additions & 0 deletions components/playground_aside.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* PlaygroundAside represents the aside content of a playground page.
*/
export default function PlaygroundAside(
props: { id?: string; version: string },
) {
return (
<>
<h2>On this page</h2>
<p>
{props.id
? <a href={`/p/${props.id}`}>p/{props.id}</a>
: <em>Unsaved</em>}
</p>
<p>
Using jsonx version{" "}
<a href={makeVersionURL(props.version)}>{props.version}</a>
</p>
</>
);
}

function makeVersionURL(version: string) {
return `https://jsr.io/@fartlabs/jsonx@${version}`;
}
29 changes: 29 additions & 0 deletions components/toc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { FSItem, Node } from "#/lib/docs/mod_client.ts";

/**
* ToCProps are the properties for the ToC component.
*/
export interface ToCProps {
nodes: Node<FSItem>[];
filter?: (node: Node<FSItem>) => boolean;
}

/**
* ToC is a recursive component that renders a table of contents.
*/
export default function ToC(props: ToCProps) {
return (
<ul>
{props.nodes.map((node) => (
<li>
{node.title && (
<a href={node.href ?? `/${node.name.join("/")}`}>{node.title}</a>
)}
{node.children && (props.filter?.(node) ?? true) && (
<ToC nodes={node.children} filter={props.filter} />
)}
</li>
))}
</ul>
);
}
9 changes: 9 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@
"@fartlabs/jsonx": "jsr:@fartlabs/jsonx@^0.0.10",
"@preact/signals": "https://esm.sh/*@preact/[email protected]",
"@preact/signals-core": "https://esm.sh/*@preact/[email protected]",
"@std/front-matter": "jsr:@std/front-matter@^0.220.1",
"@std/front-matter/any": "jsr:@std/front-matter@^0.220.1/any",
"@std/fs": "jsr:@std/fs@^0.220.1",
"@std/http": "jsr:@std/http@^0.220.1",
"@std/path": "jsr:@std/path@^0.220.1",
"@std/semver": "jsr:@std/semver@^0.220.1",
"@std/ulid": "jsr:@std/ulid@^0.220.1",
"@std/yaml": "jsr:@std/yaml@^0.220.1",
"highlight.js": "https://esm.sh/[email protected]",
"markdown-it": "https://esm.sh/[email protected]",
"markdown-it-anchor": "https://esm.sh/[email protected]",
"markdown-it-toc-done-right": "https://esm.sh/[email protected]",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/"
},
Expand Down
8 changes: 8 additions & 0 deletions docs/00_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Overview
playground: 'example:01_animals.tsx'
---

# Overview

The jsonx library exposes a JSX runtime for composing JSON data.
Loading