- Integración de 93 capítulos del manual completo - Componente MarkdownViewer para renderizar archivos .md - Navegación jerárquica completa (ManualIndex) - Sistema de búsqueda mejorado - Página ManualViewer con navegación anterior/siguiente - Scripts de verificación del manual - Puerto configurado en 8096 - Configuración de despliegue (Vercel, Netlify, GitHub Pages) - Todos los problemas detectados corregidos
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
/**
|
|
* Utilidades para procesar Markdown y extraer front matter
|
|
*/
|
|
|
|
import { matter } from 'vfile-matter';
|
|
import { unified } from 'unified';
|
|
import remarkParse from 'remark-parse';
|
|
import remarkFrontmatter from 'remark-frontmatter';
|
|
|
|
export interface FrontMatter {
|
|
version?: string;
|
|
fecha?: string;
|
|
tipo?: string;
|
|
[key: string]: any;
|
|
}
|
|
|
|
/**
|
|
* Extrae el front matter de un archivo Markdown
|
|
*/
|
|
export function extractFrontMatter(content: string): {
|
|
frontMatter: FrontMatter;
|
|
content: string;
|
|
} {
|
|
try {
|
|
const processor = unified()
|
|
.use(remarkParse)
|
|
.use(remarkFrontmatter, { type: 'yaml', marker: '-' })
|
|
.use(() => (tree, file) => {
|
|
matter(file);
|
|
});
|
|
|
|
const file = processor.processSync({ value: content, path: 'file.md' });
|
|
const frontMatter = (file.data.matter as FrontMatter) || {};
|
|
|
|
// Remover front matter del contenido si existe
|
|
const frontMatterRegex = /^---\s*\n([\s\S]*?)\n---\s*\n/;
|
|
const cleanedContent = content.replace(frontMatterRegex, '');
|
|
|
|
return {
|
|
frontMatter,
|
|
content: cleanedContent,
|
|
};
|
|
} catch (error) {
|
|
console.warn('Error extrayendo front matter:', error);
|
|
return {
|
|
frontMatter: {},
|
|
content,
|
|
};
|
|
}
|
|
}
|