fix: add null checks to parsers and fix docs path
This commit is contained in:
@@ -5,12 +5,13 @@ import { parseMarkdown, buildFileTree } from '@/lib/parser'
|
||||
import type { DocFile, ParsedDoc } from '@/lib/types'
|
||||
import { config } from '@/config'
|
||||
|
||||
const modules = import.meta.glob('../docs/**/*.md', { as: 'raw', eager: true })
|
||||
const modules = import.meta.glob('../docs/api/**/*.md', { as: 'raw', eager: true })
|
||||
|
||||
const DOCS_FILES: Record<string, string> = Object.fromEntries(
|
||||
Object.entries(modules).map(([path, content]) => {
|
||||
const relativePath = path.replace('../docs/', '')
|
||||
return [relativePath, content as string]
|
||||
const relativePath = path.replace('../docs/api/', '')
|
||||
const fileContent = typeof content === 'string' ? content : ''
|
||||
return [relativePath, fileContent]
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
@@ -41,12 +41,14 @@ export interface BlueprintData {
|
||||
}
|
||||
|
||||
function extractYamlBlock(markdown: string, sectionName: string): string {
|
||||
if (!markdown || typeof markdown !== 'string') return '';
|
||||
const pattern = new RegExp(`# ${sectionName}[\\s\\S]*?\`\`\`yaml\\n([\\s\\S]*?)\n\`\`\``, 'i');
|
||||
const match = markdown.match(pattern);
|
||||
return match ? match[1].trim() : '';
|
||||
return match ? (match[1] || '').trim() : '';
|
||||
}
|
||||
|
||||
function parseSubsystems(yaml: string): Subsystem[] {
|
||||
if (!yaml || typeof yaml !== 'string') return [];
|
||||
const subsystems: Subsystem[] = [];
|
||||
const lines = yaml.split('\n');
|
||||
|
||||
@@ -159,6 +161,7 @@ function parseSubsystems(yaml: string): Subsystem[] {
|
||||
}
|
||||
|
||||
function parseModules(yaml: string): Module[] {
|
||||
if (!yaml || typeof yaml !== 'string') return [];
|
||||
const modules: Module[] = [];
|
||||
const lines = yaml.split('\n');
|
||||
|
||||
@@ -270,6 +273,14 @@ function parseModules(yaml: string): Module[] {
|
||||
}
|
||||
|
||||
export function parseBlueprintFromMd(markdown: string): BlueprintData {
|
||||
if (!markdown || typeof markdown !== 'string') {
|
||||
return {
|
||||
meta: { name: 'Unknown', version: '0.0.0', type: 'unknown', description: '', target_runtime: '' },
|
||||
subsystems: [],
|
||||
modules: []
|
||||
};
|
||||
}
|
||||
|
||||
const metaYaml = extractYamlBlock(markdown, 'SYSTEM_META');
|
||||
const structureYaml = extractYamlBlock(markdown, 'SYSTEM_STRUCTURE');
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ const HR_REGEX = /^---+$/
|
||||
const REFERENCE_REGEX = /@see\s+([^\s]+)/g
|
||||
|
||||
export function parseMarkdown(content: string): ParsedDoc {
|
||||
if (!content || typeof content !== 'string') {
|
||||
return { title: '', metadata: {}, sections: [], references: [] };
|
||||
}
|
||||
|
||||
const lines = content.split('\n')
|
||||
const result: ParsedDoc = {
|
||||
title: '',
|
||||
|
||||
Reference in New Issue
Block a user