Skip to content

Commit 480539b

Browse files
committed
Enhance MDX component rendering with Mermaid support and update site name in OG docs
1 parent 04625d5 commit 480539b

4 files changed

Lines changed: 76 additions & 2 deletions

File tree

src/app/og/docs/[...slug]/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function GET(
1818
<DefaultImage
1919
title={page.data.title}
2020
description={page.data.description}
21-
site="My App"
21+
site="BetterScript"
2222
/>
2323
),
2424
{

src/app/robots.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { MetadataRoute } from 'next';
2+
3+
export default function robots(): MetadataRoute.Robots {
4+
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000';
5+
return {
6+
rules: {
7+
userAgent: '*',
8+
allow: '/',
9+
},
10+
sitemap: `${siteUrl.replace(/\/$/, '')}/sitemap.xml`,
11+
};
12+
}
13+
14+

src/app/sitemap.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { MetadataRoute } from 'next';
2+
import { source } from '@/lib/source';
3+
4+
export default function sitemap(): MetadataRoute.Sitemap {
5+
const siteUrl = (process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000').replace(/\/$/, '');
6+
7+
const docsEntries = source.getPages().map((page) => {
8+
const url = `${siteUrl}${page.url}`;
9+
return {
10+
url,
11+
changeFrequency: 'weekly' as const,
12+
priority: 0.7,
13+
};
14+
});
15+
16+
return [
17+
{ url: `${siteUrl}/`, changeFrequency: 'weekly', priority: 0.8 },
18+
{ url: `${siteUrl}/docs`, changeFrequency: 'weekly', priority: 0.8 },
19+
...docsEntries,
20+
];
21+
}
22+
23+

src/mdx-components.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import defaultMdxComponents from 'fumadocs-ui/mdx';
2-
import * as TabsComponents from 'fumadocs-ui/components/tabs';[[]]
2+
import * as TabsComponents from 'fumadocs-ui/components/tabs';
33
import type { MDXComponents } from 'mdx/types';
4+
import React from 'react';
45
import { Mermaid } from './components/mermaid';
56

67
// use this function to get MDX components, you will need it for rendering MDX
@@ -10,5 +11,41 @@ export function getMDXComponents(components?: MDXComponents): MDXComponents {
1011
...TabsComponents,
1112
...components,
1213
Mermaid,
14+
// Auto-render ```mermaid code fences using our Mermaid component
15+
pre: (props: any) => {
16+
const DefaultPre = (components?.pre ?? defaultMdxComponents.pre) as
17+
| React.ComponentType<any>
18+
| undefined;
19+
20+
const child: any = props?.children;
21+
const codeElement = Array.isArray(child)
22+
? child.find((c) => c?.type === 'code' || c?.props?.className)
23+
: child;
24+
const className: string | undefined =
25+
codeElement?.props?.className ?? props?.className;
26+
27+
// Recursively extract text from possible nested token structures
28+
const extractText = (node: any): string => {
29+
if (node == null) return '';
30+
if (typeof node === 'string') return node;
31+
if (Array.isArray(node)) return node.map(extractText).join('');
32+
if (typeof node === 'object' && 'props' in node) {
33+
return extractText((node as any).props?.children);
34+
}
35+
return '';
36+
};
37+
38+
const code = extractText(codeElement?.props?.children);
39+
40+
if (className && className.includes('language-mermaid') && code) {
41+
return <Mermaid chart={code.trimEnd()} />;
42+
}
43+
44+
return DefaultPre ? (
45+
<DefaultPre {...props} />
46+
) : (
47+
<pre {...props} />
48+
);
49+
},
1350
};
1451
}

0 commit comments

Comments
 (0)