Skip to content

Commit

Permalink
Integrate TypeDoc output into new docs site (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate authored Jun 29, 2024
1 parent aefafe4 commit 1766db4
Show file tree
Hide file tree
Showing 52 changed files with 448 additions and 132 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
node_modules
.turbo
/packages/*/dist
/packages/*/public
/packages/*/docs.json
/packages/*/docs
/lib/*/lib
/lib/*/debug
/lib/*/release
Expand Down
3 changes: 2 additions & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# generated content
.map.ts
.contentlayer
/content/*/api

# test & build
/coverage
Expand All @@ -24,4 +25,4 @@ yarn-error.log*
# others
.env*.local
.vercel
next-env.d.ts
next-env.d.ts
88 changes: 88 additions & 0 deletions docs/app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import Logo from '@/app/logo';
import { loaders } from '@/app/source';
import { Toggle } from '@/app/toggle';
import { DocsPage, DocsBody } from 'fumadocs-ui/page';
import { notFound } from 'next/navigation';
import { DocsLayout } from 'fumadocs-ui/layout';
import type { Metadata } from 'next';

export default async function Page({
params,
}: {
params: { slug?: string[] };
}) {
if (!params.slug) {
notFound();
}

const root = params.slug[0];
const loader = loaders.get(root);
if (!loader) {
notFound();
}

const page = loader.getPage(params.slug.slice(1));

if (page == null) {
notFound();
}

const MDX = page.data.exports.default;

return (
<DocsLayout
tree={loader.pageTree}
githubUrl={'https://github.com/TooTallNate/nx.js'}
nav={{
transparentMode: 'top',
title: (
<>
<Logo className='w-5 md:w-6 drop-shadow' /> nx.js
</>
),
}}
sidebar={{
banner: <Toggle />,
}}
>
<DocsPage toc={page.data.exports.toc}>
<DocsBody>
<h1>{page.data.title}</h1>
<p className='mb-8 text-lg text-muted-foreground'>
{page.data.description}
</p>
<MDX />
</DocsBody>
</DocsPage>
</DocsLayout>
);
}

export async function generateStaticParams() {
return Array.from(loaders.entries()).flatMap(([root, loader]) =>
loader.getPages().map((page) => ({
slug: [root].concat(page.slugs),
})),
);
}

export function generateMetadata({ params }: { params: { slug?: string[] } }) {
if (!params.slug) {
notFound();
}

const root = params.slug[0];
const loader = loaders.get(root);
if (!loader) {
notFound();
}

const page = loader.getPage(params.slug.slice(1));

if (page == null) notFound();

return {
title: page.data.title,
description: page.data.description,
} satisfies Metadata;
}
16 changes: 9 additions & 7 deletions docs/app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { getPages } from '@/app/source';
import { loaders } from '@/app/source';
import { createSearchAPI } from 'fumadocs-core/search/server';

export const { GET } = createSearchAPI('advanced', {
indexes: getPages().map((page) => ({
title: page.data.title,
structuredData: page.data.exports.structuredData,
id: page.url,
url: page.url,
})),
indexes: Array.from(loaders.values()).flatMap((loader) =>
loader.getPages().map((page) => ({
title: page.data.title,
structuredData: page.data.exports.structuredData,
id: page.url,
url: page.url,
})),
),
});
47 changes: 0 additions & 47 deletions docs/app/docs/[[...slug]]/page.tsx

This file was deleted.

24 changes: 0 additions & 24 deletions docs/app/docs/layout.tsx

This file was deleted.

11 changes: 7 additions & 4 deletions docs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ export default function HomePage() {
</h2>
</div>
<p className='text-muted-foreground'>
Go to{' '}
<Link href='/docs' className='text-foreground font-semibold underline'>
/docs
Go to the{' '}
<Link
href='/runtime'
className='text-foreground font-semibold underline'
>
Getting Started
</Link>{' '}
to read the documentation.
page to jump into the documentation.
</p>
<div className='flex text-5xl gap-8'>
<a
Expand Down
23 changes: 18 additions & 5 deletions docs/app/source.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { join } from 'node:path';
import { readdirSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { map } from '@/.map';
import { createMDXSource } from 'fumadocs-mdx';
import { loader } from 'fumadocs-core/source';

export const { getPage, getPages, pageTree } = loader({
baseUrl: '/docs',
rootDir: 'docs',
source: createMDXSource(map),
});
const contentDir = join(fileURLToPath(import.meta.url), '../../content');

export const loaders: Map<
string,
ReturnType<typeof loader<{ source: ReturnType<typeof createMDXSource> }>>
> = new Map(
readdirSync(contentDir).map((name) => [
name,
loader({
baseUrl: `/${name}`,
rootDir: name,
source: createMDXSource(map),
}),
]),
);
29 changes: 29 additions & 0 deletions docs/app/toggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { TbGlobe, TbBrowser, TbBrandPowershell } from 'react-icons/tb';
import { RootToggle } from 'fumadocs-ui/components/layout/root-toggle';

export function Toggle() {
return (
<RootToggle
options={[
{
title: 'Runtime',
description: 'Global APIs',
url: '/runtime',
icon: <TbGlobe size={24} />,
},
{
title: '@nx.js/http',
description: 'HTTP server for nx.js',
url: '/http',
icon: <TbBrowser size={24} />,
},
{
title: '@nx.js/repl',
description: 'Read-Eval-Print Loop for nx.js',
url: '/repl',
icon: <TbBrandPowershell size={24} />,
},
]}
/>
);
}
35 changes: 35 additions & 0 deletions docs/content/http/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Installation
---

<InstallTabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab value='npm'>

```bash
npm install @nx.js/http
```

</Tab>
<Tab value="pnpm">

```bash
pnpm add @nx.js/http
```

</Tab>
<Tab value='yarn'>

```bash
yarn add @nx.js/http
```

</Tab>
<Tab value='bun'>

```bash
bun add @nx.js/http
```

</Tab>

</InstallTabs>
4 changes: 4 additions & 0 deletions docs/content/http/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"pages": ["--- Usage ---", "index", "--- API Reference ---", "...api"]
}
35 changes: 35 additions & 0 deletions docs/content/repl/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Installation
---

<InstallTabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab value='npm'>

```bash
npm install @nx.js/repl
```

</Tab>
<Tab value="pnpm">

```bash
pnpm add @nx.js/repl
```

</Tab>
<Tab value='yarn'>

```bash
yarn add @nx.js/repl
```

</Tab>
<Tab value='bun'>

```bash
bun add @nx.js/repl
```

</Tab>

</InstallTabs>
4 changes: 4 additions & 0 deletions docs/content/repl/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"pages": ["--- Usage ---", "index", "--- API Reference ---", "...api"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Bootstraping your nx.js app
---

> This guide assumes that you have a homebrew enabled Switch. If you don't,
> you can follow the [Switch Homebrew Guide](https://nh-server.github.io/switch-guide/)
> you can follow the [NH Switch Guide](https://nh-server.github.io/switch-guide/)
> to get started.
>
> It is also assumes that you have [Node.js](https://nodejs.org) installed on your
Expand Down Expand Up @@ -95,8 +95,8 @@ this file to Switch via FTP or directly copy it to the SD card, and then launch
## More information

<Cards>
<Card title="Customizing package metadata and icon" href="/docs/metadata" />
<Card title="Learn about the available rendering mode APIs" href="/docs/rendering" />
<Card title="Customizing package metadata and icon" href="/runtime/metadata" />
<Card title="Learn about the available rendering mode APIs" href="/runtime/rendering" />
</Cards>

[`esbuild`]: https://esbuild.github.io
[`esbuild`]: https://esbuild.github.io
Loading

0 comments on commit 1766db4

Please sign in to comment.