From 4898ee54340d3fa5df6394606406d7ebe2bb856b Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Wed, 18 Mar 2026 16:13:57 +0800 Subject: [PATCH] fix: add null checks to parsers and fix docs path --- src/components/ApiDocViewer.tsx | 7 ++++--- src/data/blueprintParser.ts | 13 ++++++++++++- src/docs/{ => api}/authentication.md | 0 src/docs/{ => api}/errors.md | 0 src/docs/{ => api}/getting-started.md | 0 src/docs/{ => api}/guide/installation.md | 0 src/docs/{ => api}/users.md | 0 src/lib/parser.ts | 4 ++++ 8 files changed, 20 insertions(+), 4 deletions(-) rename src/docs/{ => api}/authentication.md (100%) rename src/docs/{ => api}/errors.md (100%) rename src/docs/{ => api}/getting-started.md (100%) rename src/docs/{ => api}/guide/installation.md (100%) rename src/docs/{ => api}/users.md (100%) diff --git a/src/components/ApiDocViewer.tsx b/src/components/ApiDocViewer.tsx index 77c4ac3..b8c7446 100644 --- a/src/components/ApiDocViewer.tsx +++ b/src/components/ApiDocViewer.tsx @@ -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 = 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] }) ) diff --git a/src/data/blueprintParser.ts b/src/data/blueprintParser.ts index 885edfe..028aaa0 100644 --- a/src/data/blueprintParser.ts +++ b/src/data/blueprintParser.ts @@ -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'); diff --git a/src/docs/authentication.md b/src/docs/api/authentication.md similarity index 100% rename from src/docs/authentication.md rename to src/docs/api/authentication.md diff --git a/src/docs/errors.md b/src/docs/api/errors.md similarity index 100% rename from src/docs/errors.md rename to src/docs/api/errors.md diff --git a/src/docs/getting-started.md b/src/docs/api/getting-started.md similarity index 100% rename from src/docs/getting-started.md rename to src/docs/api/getting-started.md diff --git a/src/docs/guide/installation.md b/src/docs/api/guide/installation.md similarity index 100% rename from src/docs/guide/installation.md rename to src/docs/api/guide/installation.md diff --git a/src/docs/users.md b/src/docs/api/users.md similarity index 100% rename from src/docs/users.md rename to src/docs/api/users.md diff --git a/src/lib/parser.ts b/src/lib/parser.ts index 76ab84c..8d481e2 100644 --- a/src/lib/parser.ts +++ b/src/lib/parser.ts @@ -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: '',