-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87eca1d
commit cf8f201
Showing
12 changed files
with
241 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,34 @@ | ||
export default function Page() { | ||
return 'Docs Category Page' | ||
import { Mdx } from '@/build-app/components/Mdx' | ||
import { TableOfContent } from '@/build-app/components/TableOfContent' | ||
import { getPageContent } from '@/build-app/utils/page-content' | ||
import Link from 'next/link' | ||
import { notFound } from 'next/navigation' | ||
|
||
type PageProps = { | ||
params: { | ||
page: string | ||
category: string | ||
} | ||
} | ||
|
||
export default function Page({ params }: PageProps) { | ||
const { page, category } = params | ||
|
||
const { content, tree } = getPageContent(`${category}/${page}.mdx`, true) | ||
|
||
return content === 'Not Found' ? ( | ||
notFound() | ||
) : ( | ||
<div> | ||
<div> | ||
<Link href={`/docs/${category}`}>Go to main page</Link> | ||
</div> | ||
<div style={{ display: 'flex' }}> | ||
<main> | ||
<Mdx>{content}</Mdx> | ||
</main> | ||
<TableOfContent tree={tree} /> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Toc } from '@/build-app/utils/page-tree' | ||
import Link from 'next/link' | ||
|
||
type TableOfContentProps = { | ||
tree?: Toc[] | ||
} | ||
|
||
export function TableOfContent({ tree }: TableOfContentProps) { | ||
if (!tree) return null | ||
|
||
return ( | ||
<ul> | ||
{tree.map(item => ( | ||
<li> | ||
<Link href={item.href}>{item.title}</Link> | ||
{item.children && ( | ||
<ul> | ||
{item.children.map(child => ( | ||
<Link href={child.href}>{child.title}</Link> | ||
))} | ||
</ul> | ||
)} | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { unified } from 'unified' | ||
import rehypeParse from 'rehype-parse' | ||
import { marked } from 'marked' | ||
import { visit } from 'unist-util-visit' | ||
import slugify from 'slugify' | ||
|
||
export type TocITem = { | ||
id: string | ||
title: string | ||
href: string | ||
} | ||
|
||
export type Toc = TocITem & { | ||
children?: TocITem[] | ||
} | ||
|
||
export function getPageTree(content?: string) { | ||
if (!content) return | ||
|
||
const tree = unified().use(rehypeParse, { fragment: true }).parse(marked(content)) | ||
|
||
const tableOfContents = [] as Toc[] | ||
|
||
visit(tree, 'element', node => { | ||
if (node.tagName === 'h2') { | ||
// @ts-ignore | ||
const title = node.children[0]?.value | ||
const id = slugify(title.toLowerCase()) | ||
|
||
tableOfContents.push({ id, title, href: `#${id}` }) | ||
} | ||
|
||
if (node.tagName === 'h3') { | ||
const parentHeading = tableOfContents[tableOfContents.length - 1] | ||
|
||
if (!parentHeading) return | ||
|
||
// @ts-ignore | ||
const title = node.children[0].value | ||
const id = slugify(title.toLowerCase()) | ||
|
||
parentHeading.children = parentHeading.children || [] | ||
parentHeading.children.push({ id, title, href: `#${id}` }) | ||
} | ||
}) | ||
|
||
return tableOfContents | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Gets the pages tree for design | ||
*/ | ||
export function getDesignPages() { | ||
return {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {} | ||
const nextConfig = { | ||
output: 'export', | ||
} | ||
|
||
module.exports = nextConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.