diff --git a/src/components/Doc.tsx b/src/components/Doc.tsx index 76d6c94c..7ffc7c72 100644 --- a/src/components/Doc.tsx +++ b/src/components/Doc.tsx @@ -9,6 +9,8 @@ import { renderMarkdown } from '~/utils/markdown' import { DocBreadcrumb } from './DocBreadcrumb' import { MarkdownContent } from '~/components/markdown' import type { ConfigSchema } from '~/utils/config' +import { useLocalCurrentFramework } from './FrameworkSelect' +import { useParams } from '@tanstack/react-router' type DocProps = { title: string @@ -28,6 +30,8 @@ type DocProps = { config?: ConfigSchema // Footer content rendered after markdown footer?: React.ReactNode + // Optional framework to use (overrides URL and local storage) + framework?: string } export function Doc({ @@ -45,6 +49,7 @@ export function Doc({ pagePath, config, footer, + framework: frameworkProp, }: DocProps) { // Extract headings synchronously during render to avoid hydration mismatch const { headings, markup } = React.useMemo( @@ -52,6 +57,18 @@ export function Doc({ [content], ) + // Get current framework from prop, URL params, or local storage + const { framework: paramsFramework } = useParams({ strict: false }) + const localCurrentFramework = useLocalCurrentFramework() + const currentFramework = React.useMemo(() => { + const fw = + frameworkProp || + paramsFramework || + localCurrentFramework.currentFramework || + 'react' + return typeof fw === 'string' ? fw.toLowerCase() : fw + }, [frameworkProp, paramsFramework, localCurrentFramework.currentFramework]) + const isTocVisible = shouldRenderToc && headings.length > 1 const markdownContainerRef = React.useRef(null) @@ -170,6 +187,7 @@ export function Doc({ colorFrom={colorFrom} colorTo={colorTo} textColor={textColor} + currentFramework={currentFramework} /> )} diff --git a/src/components/Toc.tsx b/src/components/Toc.tsx index b4c4f84c..7c23519d 100644 --- a/src/components/Toc.tsx +++ b/src/components/Toc.tsx @@ -18,9 +18,29 @@ type TocProps = { colorTo?: string textColor?: string activeHeadings: Array + currentFramework?: string } -export function Toc({ headings, textColor, activeHeadings }: TocProps) { +export function Toc({ + headings, + textColor, + activeHeadings, + currentFramework, +}: TocProps) { + // Filter headings based on framework scope + const visibleHeadings = React.useMemo(() => { + return headings.filter((heading) => { + console.log(heading) + if (heading.framework) { + return ( + currentFramework && + heading.framework === currentFramework.toLowerCase() + ) + } + // If no framework attribute, always show (not framework-scoped) + return true + }) + }, [headings, currentFramework]) return (