mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 00:19:08 +00:00
The sidebar for the management api introduction is eating into the main content unfairly given its amount of importance (three links). Also, most of our content has a richer sidebar with more ways to interact. What started as an attempt to give more space for the main content in the management api introduction turned into an attempt to standardize the sidebar similar to how its being used on other pages. The "Additional links" now live in the sidebar and fall back to a list under the article below the md breakpoint. PR: https://github.com/supabase/supabase/pull/52107
69 lines
2.6 KiB
TypeScript
69 lines
2.6 KiB
TypeScript
import { readFile } from 'node:fs/promises'
|
|
import { join } from 'node:path'
|
|
import CliGlobalFlagsHandler from '~/components/reference/enrichments/cli/CliGlobalFlagsHandler'
|
|
import { MDXRemoteBase } from '~/features/docs/MdxBase'
|
|
import { components } from '~/features/docs/MdxBase.shared'
|
|
import { RefSubLayout } from '~/features/docs/Reference.ui'
|
|
import { cache_fullProcess_withDevCacheBust } from '~/features/helpers.fs'
|
|
import { REF_DOCS_DIRECTORY } from '~/lib/docs'
|
|
import matter from 'gray-matter'
|
|
import { type ComponentProps } from 'react'
|
|
|
|
import { CodeBlock } from '../ui/CodeBlock/CodeBlock'
|
|
|
|
async function readRefMdx(relPath: string) {
|
|
const fullPath = join(REF_DOCS_DIRECTORY, relPath + '.mdx')
|
|
|
|
try {
|
|
if (!fullPath.startsWith(REF_DOCS_DIRECTORY)) {
|
|
throw Error(`Accessing forbidden path outside of REF_DOCS_DIRECTORY: ${fullPath}`)
|
|
}
|
|
|
|
const mdx = await readFile(fullPath, 'utf-8')
|
|
return matter(mdx)
|
|
} catch (err) {
|
|
console.error(`Error fetching reference markdown from file: ${fullPath}:\n\n${err}`)
|
|
return { content: '', data: {} as Record<string, unknown> }
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Caching this for the entire process is fine because the Markdown content is
|
|
* baked into each deployment and cannot change. There's also nothing sensitive
|
|
* here: this is just reading the public MDX files from the codebase.
|
|
*/
|
|
const getRefMarkdown = cache_fullProcess_withDevCacheBust(
|
|
async (relPath: string) => (await readRefMdx(relPath)).content,
|
|
REF_DOCS_DIRECTORY,
|
|
(filename: string) => JSON.stringify([filename.replace(/\.mdx$/, '')])
|
|
)
|
|
|
|
const getRefFrontmatter = cache_fullProcess_withDevCacheBust(
|
|
async (relPath: string) => (await readRefMdx(relPath)).data,
|
|
REF_DOCS_DIRECTORY,
|
|
(filename: string) => JSON.stringify([filename.replace(/\.mdx$/, '')])
|
|
)
|
|
|
|
interface MDXRemoteRefsProps {
|
|
source: string
|
|
codeBlockProps?: Partial<ComponentProps<typeof CodeBlock>>
|
|
}
|
|
|
|
function MDXRemoteRefs({ source, codeBlockProps }: MDXRemoteRefsProps) {
|
|
const refComponents = {
|
|
...components,
|
|
// Override the CodeBlock used for normal guides to skip type generation
|
|
// because it is too resource-intensive
|
|
pre: (props: ComponentProps<typeof CodeBlock>) => (
|
|
<CodeBlock {...props} {...codeBlockProps} skipTypeGeneration />
|
|
),
|
|
RefSubLayout,
|
|
CliGlobalFlagsHandler,
|
|
}
|
|
|
|
// @ts-expect-error: Gildas - This is because RefSubLayout is a namespace containing multiple components. It works but the MDXClient types are stricter
|
|
return <MDXRemoteBase source={source} components={refComponents} />
|
|
}
|
|
|
|
export { getRefFrontmatter, getRefMarkdown, MDXRemoteRefs }
|