Skip to content

Commit 2eb0d79

Browse files
authored
Hide disabled pages from LLMs (#128)
1 parent c436413 commit 2eb0d79

File tree

4 files changed

+168
-238
lines changed

4 files changed

+168
-238
lines changed

src/lib/utils.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,67 @@ import { twMerge } from 'tailwind-merge';
44
export function cn(...inputs: ClassValue[]) {
55
return twMerge(clsx(inputs));
66
}
7+
8+
export function cleanMdxContent(content: string): string {
9+
// Remove MDX import statements at the start of the file
10+
content = content.replace(
11+
/^(\s*import\s+.*?(?:from\s+['"].*?['"])?;?\s*\n)+/m,
12+
'',
13+
);
14+
15+
// Process Tabs components - extract TabItem contents
16+
content = content.replace(/<Tabs>[\s\S]*?<\/Tabs>/g, (match) => {
17+
const results: string[] = [];
18+
const tabItemRegex =
19+
/<TabItem[^>]*label="([^"]*)"[^>]*>([\s\S]*?)(?=<TabItem|<\/Tabs>)/g;
20+
21+
for (const [, label, tabContent] of match.matchAll(tabItemRegex)) {
22+
const cleanContent = tabContent.replace(/<\/TabItem>\s*$/, '').trim();
23+
if (cleanContent) {
24+
results.push(`**${label}:**\n${cleanContent}`);
25+
}
26+
}
27+
28+
return results.length > 0 ? results.join('\n\n') : '';
29+
});
30+
31+
// Process CardGrid/LinkCard components - convert to markdown links
32+
content = content.replace(/<CardGrid[^>]*>[\s\S]*?<\/CardGrid>/g, (match) => {
33+
const links: string[] = [];
34+
const linkCardRegex =
35+
/<LinkCard\s+[^>]*href="([^"]*)"[^>]*title="([^"]*)"[^>]*description="([^"]*)"[^>]*\/>/g;
36+
37+
for (const [, href, title, description] of match.matchAll(linkCardRegex)) {
38+
const fullUrl = href.startsWith('/')
39+
? `https://docs.sprites.dev${href}`
40+
: href;
41+
links.push(`- [${title}](${fullUrl}) - ${description}`);
42+
}
43+
44+
return links.length > 0 ? links.join('\n') : '';
45+
});
46+
47+
// Remove self-closing JSX/MDX components
48+
content = content.replace(/<[A-Z][a-zA-Z]*\s+[^>]*\/>/g, '');
49+
50+
// Handle Callout components - keep content
51+
content = content.replace(
52+
/<Callout[^>]*>([\s\S]*?)<\/Callout>/g,
53+
(_, inner) => inner.trim(),
54+
);
55+
56+
// Remove remaining JSX component tags
57+
content = content.replace(/<[A-Z][a-zA-Z]*[^>]*>/g, '');
58+
content = content.replace(/<\/[A-Z][a-zA-Z]*>/g, '');
59+
60+
// Convert relative links to fully qualified URLs
61+
content = content.replace(
62+
/\[([^\]]+)\]\(\/([^)]*)\)/g,
63+
(_, text, path) => `[${text}](https://docs.sprites.dev/${path})`,
64+
);
65+
66+
// Clean up excessive blank lines
67+
content = content.replace(/\n{4,}/g, '\n\n\n');
68+
69+
return content.trim();
70+
}

src/pages/[...slug].md.ts

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,20 @@
11
import { getCollection } from 'astro:content';
22
import type { APIRoute, GetStaticPaths } from 'astro';
33

4+
import { cleanMdxContent } from '@/lib/utils';
5+
46
export const prerender = true;
57

68
export const getStaticPaths: GetStaticPaths = async () => {
7-
const docs = await getCollection('docs');
9+
const docs = await getCollection('docs', ({ data }) => {
10+
return data.draft !== true;
11+
});
812
return docs.map((doc) => ({
913
params: { slug: doc.id },
1014
props: { doc },
1115
}));
1216
};
1317

14-
function cleanMdxContent(content: string): string {
15-
// Remove MDX import statements at the start of the file
16-
content = content.replace(
17-
/^(\s*import\s+.*?(?:from\s+['"].*?['"])?;?\s*\n)+/m,
18-
'',
19-
);
20-
21-
// Process Tabs components - extract TabItem contents
22-
content = content.replace(/<Tabs>[\s\S]*?<\/Tabs>/g, (match) => {
23-
const results: string[] = [];
24-
const tabItemRegex =
25-
/<TabItem[^>]*label="([^"]*)"[^>]*>([\s\S]*?)(?=<TabItem|<\/Tabs>)/g;
26-
27-
for (const [, label, tabContent] of match.matchAll(tabItemRegex)) {
28-
const cleanContent = tabContent.replace(/<\/TabItem>\s*$/, '').trim();
29-
if (cleanContent) {
30-
results.push(`**${label}:**\n${cleanContent}`);
31-
}
32-
}
33-
34-
return results.length > 0 ? results.join('\n\n') : '';
35-
});
36-
37-
// Process CardGrid/LinkCard components - convert to markdown links
38-
content = content.replace(/<CardGrid[^>]*>[\s\S]*?<\/CardGrid>/g, (match) => {
39-
const links: string[] = [];
40-
const linkCardRegex =
41-
/<LinkCard\s+[^>]*href="([^"]*)"[^>]*title="([^"]*)"[^>]*description="([^"]*)"[^>]*\/>/g;
42-
43-
for (const [, href, title, description] of match.matchAll(linkCardRegex)) {
44-
const fullUrl = href.startsWith('/')
45-
? `https://docs.sprites.dev${href}`
46-
: href;
47-
links.push(`- [${title}](${fullUrl}) - ${description}`);
48-
}
49-
50-
return links.length > 0 ? links.join('\n') : '';
51-
});
52-
53-
// Remove self-closing JSX/MDX components
54-
content = content.replace(/<[A-Z][a-zA-Z]*\s+[^>]*\/>/g, '');
55-
56-
// Handle Callout components - keep content
57-
content = content.replace(
58-
/<Callout[^>]*>([\s\S]*?)<\/Callout>/g,
59-
(_, inner) => inner.trim(),
60-
);
61-
62-
// Remove remaining JSX component tags
63-
content = content.replace(/<[A-Z][a-zA-Z]*[^>]*>/g, '');
64-
content = content.replace(/<\/[A-Z][a-zA-Z]*>/g, '');
65-
66-
// Convert relative links to fully qualified URLs
67-
content = content.replace(
68-
/\[([^\]]+)\]\(\/([^)]*)\)/g,
69-
(_, text, path) => `[${text}](https://docs.sprites.dev/${path})`,
70-
);
71-
72-
// Clean up excessive blank lines
73-
content = content.replace(/\n{4,}/g, '\n\n\n');
74-
75-
return content.trim();
76-
}
77-
7818
export const GET: APIRoute = async ({ props }) => {
7919
const { doc } = props as {
8020
doc: {

0 commit comments

Comments
 (0)