Files
supabase/apps/docs/components/GuidesTableOfContents.tsx
Jonathan Summers-Muir 2bfb7187ab Add .mdx raw API and copy-as-markdown feature
Introduce an API endpoint that serves preprocessed Markdown for guide pages (.mdx) and a client "Copy as Markdown" button. Adds mdxToMarkdown transformer to convert MDX/JSX (admonitions, Image, other components) into plain Markdown, a test script to scan guides for unhandled JSX, and a CopyMarkdownButton client component. Integrates the copy button into GuidesMdx template and GuidesTableOfContents (TOC now accepts children), updates next.config.mjs with rewrites and outputFileTracingIncludes for the new API, and adds a navigation types reference in next-env.d.ts. The API enforces existing access checks via getGuidesMarkdown and returns Markdown with caching headers.
2026-02-26 19:47:30 +08:00

66 lines
1.8 KiB
TypeScript

'use client'
import React from 'react'
import { usePathname } from 'next/navigation'
import { isFeatureEnabled } from 'common'
import { cn } from 'ui'
import { ExpandableVideo } from 'ui-patterns/ExpandableVideo'
import { Toc, TOCItems, TOCScrollArea } from 'ui-patterns/Toc'
import { Feedback } from '~/components/Feedback'
import { useTocAnchors } from '../features/docs/GuidesMdx.state'
interface TOCHeader {
id?: string
text: string
link: string
level: number
}
const GuidesTableOfContents = ({
className,
video,
children,
}: {
className?: string
video?: string
children?: React.ReactNode
}) => {
const pathname = usePathname()
const { toc } = useTocAnchors()
const showFeedback = isFeatureEnabled('feedback:docs')
const tocVideoPreview = `https://img.youtube.com/vi/${video}/0.jpg`
return (
<div className={cn('thin-scrollbar overflow-y-auto h-fit', 'px-px', className)}>
<div className="w-full relative border-l flex flex-col gap-6 lg:gap-8 px-2 h-fit">
{video && (
<div className="relative pl-5">
<ExpandableVideo imgUrl={tocVideoPreview} videoId={video} />
</div>
)}
{showFeedback && (
<div className="pl-5">
<Feedback key={pathname} />
</div>
)}
{toc.length !== 0 && (
<Toc className="-ml-[calc(0.25rem+6px)]">
<h3 className="inline-flex items-center gap-1.5 font-mono text-xs uppercase text-foreground pl-[calc(1.5rem+6px)]">
On this page
</h3>
<TOCScrollArea>
<TOCItems items={toc} />
</TOCScrollArea>
</Toc>
)}
{children && <div className="pl-5">{children}</div>}
</div>
</div>
)
}
export default GuidesTableOfContents
export type { TOCHeader }