- Eliminated redundant components, pages, and layouts related to authentication (`login`, `register`, `password-reset`, etc.), user settings, admin, and demos. - Simplified the frontend structure by removing unused dynamic imports, forms, and test code. - Refactored configurations and metadata imports to exclude references to removed features. - Streamlined the project for future development and improved maintainability by discarding legacy and unused code.
76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
/**
|
|
* Dynamic Documentation Route
|
|
* Renders markdown files from docs/ directory
|
|
* Access: /dev/docs/design-system/01-foundations, etc.
|
|
*/
|
|
|
|
import { notFound } from 'next/navigation';
|
|
import { promises as fs } from 'fs';
|
|
import path from 'path';
|
|
import matter from 'gray-matter';
|
|
import { MarkdownContent } from '@/components/docs/MarkdownContent';
|
|
import { DevBreadcrumbs } from '@/components/dev/DevBreadcrumbs';
|
|
|
|
interface DocPageProps {
|
|
params: Promise<{ slug: string[] }>;
|
|
}
|
|
|
|
// Generate static params for all documentation files
|
|
export async function generateStaticParams() {
|
|
const docsDir = path.join(process.cwd(), 'docs', 'design-system');
|
|
|
|
try {
|
|
const files = await fs.readdir(docsDir);
|
|
const mdFiles = files.filter((file) => file.endsWith('.md'));
|
|
|
|
return mdFiles.map((file) => ({
|
|
slug: [file.replace(/\.md$/, '')],
|
|
}));
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
// Get markdown file content
|
|
async function getDocContent(slug: string[]) {
|
|
const filePath = path.join(process.cwd(), 'docs', 'design-system', ...slug) + '.md';
|
|
|
|
try {
|
|
const fileContent = await fs.readFile(filePath, 'utf-8');
|
|
const { data, content } = matter(fileContent);
|
|
|
|
return {
|
|
frontmatter: data,
|
|
content,
|
|
filePath: slug.join('/'),
|
|
};
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export default async function DocPage({ params }: DocPageProps) {
|
|
const { slug } = await params;
|
|
const doc = await getDocContent(slug);
|
|
|
|
if (!doc) {
|
|
notFound();
|
|
}
|
|
|
|
// Extract title from first heading or use filename
|
|
const title = doc.content.match(/^#\s+(.+)$/m)?.[1] || slug[slug.length - 1];
|
|
|
|
return (
|
|
<div className="bg-background">
|
|
{/* Breadcrumbs */}
|
|
<DevBreadcrumbs items={[{ label: 'Documentation', href: '/dev/docs' }, { label: title }]} />
|
|
|
|
<div className="container mx-auto px-4 py-12">
|
|
<div className="mx-auto max-w-4xl">
|
|
<MarkdownContent content={doc.content} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|