-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
14 changed files
with
5,143 additions
and
2,776 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use client' | ||
import { ApiRefNode, TypeFieldMap, RefNodeField, MarkdownApiRefDocument } from '@/app/apiDocsStructures' | ||
import React, { useEffect } from 'react' | ||
import ExpandMoreIcon from '@/app/images/expand_more.svg' | ||
import ExpandLessIcon from '@/app/images/expand_less.svg' | ||
import { useParams } from 'next/navigation' | ||
import Link from 'next/link' | ||
|
||
interface NavLink { | ||
label: string | ||
location: string | ||
} | ||
|
||
interface NavGroup { | ||
title: string | ||
links: NavLink[] | ||
} | ||
|
||
export default function NavGroup({ group }: { group: NavGroup }) { | ||
let slugParam = useParams().slug | ||
if (typeof slugParam === 'string') { | ||
slugParam = [slugParam] | ||
} | ||
const slug = (slugParam ?? []).join('/') | ||
|
||
const [expanded, setExpanded] = React.useState(() => { | ||
const currentLocation = `/editor/api/${slug}` | ||
return group.links.some(({ location }) => location === currentLocation) | ||
}) | ||
|
||
return ( | ||
<dl> | ||
<dt className="flex items-center cursor-pointer" onClick={() => setExpanded((v) => !v)}> | ||
{group.title} | ||
{expanded ? <ExpandLessIcon className="ml-auto" /> : <ExpandMoreIcon className="ml-auto" />} | ||
</dt> | ||
{expanded && | ||
group.links.map(({ location, label }, index) => { | ||
return ( | ||
<dd key={index}> | ||
<Link href={location}>{label}</Link> | ||
</dd> | ||
) | ||
})} | ||
</dl> | ||
) | ||
} |
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,96 @@ | ||
/* eslint-disable react-refresh/only-export-components */ | ||
import { getApiDocs } from '@/app/getApiDocs' | ||
import { MDXRemote } from 'next-mdx-remote/rsc' | ||
import rehypePrism from 'rehype-prism-plus' | ||
import rehypeSlug from 'rehype-slug' | ||
import rehypeRewrite from 'rehype-rewrite' | ||
import { Root, RootContent } from 'hast' | ||
import remarkGfm from 'remark-gfm' | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
import classNames from 'classnames' | ||
|
||
interface SlugParam { | ||
slug: string[] | ||
} | ||
|
||
export function generateStaticParams() { | ||
const files: SlugParam[] = [] | ||
|
||
function readFilesRecursively(currentPath: string) { | ||
const entries = fs.readdirSync(currentPath) | ||
|
||
for (const entry of entries) { | ||
const entryPath = path.join(currentPath, entry) | ||
const stat = fs.statSync(entryPath) | ||
|
||
if (stat.isDirectory()) { | ||
readFilesRecursively(entryPath) | ||
} else if (stat.isFile() && path.extname(entryPath) === '.md') { | ||
const slugParts = entryPath.replace('api-ref/', '').replace('.md', '').replace('README', '').split('/') | ||
|
||
files.push({ | ||
slug: slugParts, | ||
}) | ||
} | ||
} | ||
} | ||
|
||
readFilesRecursively('./api-ref') | ||
|
||
return files | ||
} | ||
|
||
interface PageParams { | ||
slug: string[] | ||
} | ||
|
||
export function generateMetadata({ params }: { params: PageParams }) { | ||
return {} | ||
const { docs } = getApiDocs('./api-ref') | ||
const doc = docs.find((file) => file.slug === params.slug) | ||
return { | ||
title: `${doc?.title} | MDXEditor`, | ||
description: | ||
'MDXEditor is an open-source React component that lets your users edit markdown documents naturally, just like in Google docs or Notion.', | ||
} | ||
} | ||
|
||
export default function Page({ params }: { params: PageParams }) { | ||
let slug = params.slug | ||
if (!slug) { | ||
slug = ['README'] | ||
} | ||
|
||
const pageContent = fs.readFileSync(`./api-ref/${slug.join('/')}.md`, 'utf-8') | ||
|
||
return ( | ||
<div className={classNames({ homepage: slug[0] === 'README' })}> | ||
<MDXRemote | ||
source={pageContent} | ||
options={{ | ||
mdxOptions: { | ||
remarkPlugins: [remarkGfm], | ||
rehypePlugins: [ | ||
rehypeSlug, | ||
rehypePrism, | ||
[ | ||
rehypeRewrite, | ||
{ | ||
selector: 'a', | ||
rewrite(node: Root | RootContent) { | ||
if (node.type == 'element' && node.tagName === 'a') { | ||
node.properties!.href = (node.properties!.href as string).replace(/\.md$/, '').replace('README.md', '') | ||
} | ||
}, | ||
}, | ||
], | ||
], | ||
format: 'md', | ||
}, | ||
parseFrontmatter: true, | ||
}} | ||
/> | ||
</div> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.