toc
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 3m39s

This commit is contained in:
2026-01-27 10:26:17 +01:00
parent 12501ea51a
commit 20d7d8405a
2 changed files with 32 additions and 16 deletions

View File

@@ -69,16 +69,26 @@ export const mdxComponents = {
img: (props: any) => ( img: (props: any) => (
<AnimatedImage src={props.src} alt={props.alt} /> <AnimatedImage src={props.src} alt={props.alt} />
), ),
h2: ({ children, ...props }: any) => ( h2: ({ children, ...props }: any) => {
<SplitHeading {...props} className="mt-16 mb-6 pb-3 border-b-2 border-primary/20"> const id = typeof children === 'string'
{children} ? children.toLowerCase().replace(/[^\w\s-]/g, '').replace(/\s+/g, '-')
</SplitHeading> : props.id;
), return (
h3: ({ children, ...props }: any) => ( <SplitHeading {...props} id={id} className="mt-16 mb-6 pb-3 border-b-2 border-primary/20">
<h3 {...props} className="text-2xl font-bold text-text-primary mt-12 mb-4"> {children}
{children} </SplitHeading>
</h3> );
), },
h3: ({ children, ...props }: any) => {
const id = typeof children === 'string'
? children.toLowerCase().replace(/[^\w\s-]/g, '').replace(/\s+/g, '-')
: props.id;
return (
<h3 {...props} id={id} className="text-2xl font-bold text-text-primary mt-12 mb-4">
{children}
</h3>
);
},
p: ({ children, ...props }: any) => ( p: ({ children, ...props }: any) => (
<p {...props} className="text-lg text-text-secondary leading-relaxed mb-6"> <p {...props} className="text-lg text-text-secondary leading-relaxed mb-6">
{children} {children}

View File

@@ -19,7 +19,7 @@ export default function TableOfContents({ headings, locale }: TableOfContentsPro
useEffect(() => { useEffect(() => {
const observerOptions = { const observerOptions = {
rootMargin: '-100px 0% -80% 0%', rootMargin: '-10% 0% -70% 0%',
threshold: 0 threshold: 0
}; };
@@ -31,12 +31,18 @@ export default function TableOfContents({ headings, locale }: TableOfContentsPro
}); });
}, observerOptions); }, observerOptions);
const elements = headings.map((h) => document.getElementById(h.id)); // Use a small delay to ensure MDX content is rendered and IDs are present
elements.forEach((el) => { const timer = setTimeout(() => {
if (el) observer.observe(el); const elements = headings.map((h) => document.getElementById(h.id));
}); elements.forEach((el) => {
if (el) observer.observe(el);
});
}, 500);
return () => observer.disconnect(); return () => {
clearTimeout(timer);
observer.disconnect();
};
}, [headings]); }, [headings]);
if (headings.length === 0) return null; if (headings.length === 0) return null;