Skip to content

Commit

Permalink
feat(ui/docs): add devdocs site with content
Browse files Browse the repository at this point in the history
  • Loading branch information
MFarabi619 committed Aug 3, 2024
1 parent d580558 commit 569e003
Show file tree
Hide file tree
Showing 19 changed files with 2,338 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** Auto-generated */
declare const map: Record<string, unknown>

export { map }
29 changes: 29 additions & 0 deletions mdx-components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { MDXComponents } from 'mdx/types'
import defaultComponents from 'fumadocs-ui/mdx'
import type { ReactNode } from 'react'
import { Tab, Tabs } from 'fumadocs-ui/components/tabs'
import { Step, Steps } from 'fumadocs-ui/components/steps'
import { Callout } from 'fumadocs-ui/components/callout'

export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...defaultComponents,
...components,
Tab,
Tabs,
InstallTabs: ({
items,
children,
}: {
items: string[]
children: ReactNode
}) => (
<Tabs items={items} id="package-manager">
{children}
</Tabs>
),
Step,
Steps,
Callout,
}
}
14 changes: 13 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
import createMDX from 'fumadocs-mdx/config'
import { fileGenerator, remarkDocGen, remarkInstall } from 'fumadocs-docgen'

await import('./src/env.js')

const withMDX = createMDX({
rootContentPath: './src/content',
mdxOptions: {
lastModifiedTime: 'git',
remarkPlugins: [[remarkInstall, { Tabs: 'InstallTabs' }], [remarkDocGen, { generators: [fileGenerator()] }]],
},
})

/** @type {import("next").NextConfig} */
const config = {
reactStrictMode: true,
output: 'standalone',
}

export default config
export default withMDX(config)
11 changes: 11 additions & 0 deletions src/app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createSearchAPI } from 'fumadocs-core/search/server'
import { getPages } from '@/app/docs/source'

export const { GET } = createSearchAPI('advanced', {
indexes: getPages().map(page => ({
title: page.data.title,
structuredData: page.data.exports.structuredData,
id: page.url,
url: page.url,
})),
})
72 changes: 72 additions & 0 deletions src/app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { Metadata } from 'next'
import { DocsBody, DocsPage } from 'fumadocs-ui/page'
import { notFound } from 'next/navigation'
import { Edit } from 'lucide-react'
import packageJson from '@root/package.json'
import { getPage, getPages } from '@/app/docs/source'

export default async function Page({
params,
}: {
params: { slug?: string[] }
}) {
const page = getPage(params.slug)

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

const MDX = page.data.exports.default
const path = `src/content/docs/${page.file.path}`
const gitHubRepoUrl = packageJson.repository.url.replace(/\.git$/, '') // Remove .git suffix

const footer = (
<a
href={`${gitHubRepoUrl}/blob/main/${path}`}
target="_blank"
rel="noreferrer noopener"
className="inline-flex items-center justify-center rounded-md font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 border bg-secondary text-secondary-foreground hover:bg-secondary/80 h-9 px-3 text-xs gap-1.5"
>
<Edit className="size-3" />
Edit on GitHub
</a>
)

return (
<DocsPage
toc={page.data.exports.toc}
lastUpdate={page.data.exports.lastModified}
full={page.data.full}
tableOfContent={{
footer,
}}
tableOfContentPopover={{ footer }}
>
<DocsBody>
<h1>{page.data.title}</h1>
<p className="mb-8 text-lg text-muted-foreground">
{page.data.description}
</p>
<MDX />
</DocsBody>
</DocsPage>
)
}

export async function generateStaticParams() {
return getPages().map(page => ({
slug: page.slugs,
}))
}

export function generateMetadata({ params }: { params: { slug?: string[] } }) {
const page = getPage(params.slug)

if (page == null)
notFound()

return {
title: page.data.title,
description: page.data.description,
} satisfies Metadata
}
Binary file added src/app/docs/favicon.ico
Binary file not shown.
Loading

0 comments on commit 569e003

Please sign in to comment.