const fs = require('fs'); // 读取Markdown文件 const markdownContent = fs.readFileSync('网页未导入数据/交通物流产业/学生完成的项目/自动化分拣输送线的扫码分流、气缸拨臂与卡箱监测控制.md', 'utf8'); // 解析Markdown内容并转换为sections格式 function parseMarkdownToSections(content) { const lines = content.split('\n'); const sections = []; let currentSection = null; for (let i = 0; i < lines.length; i++) { const line = lines[i]; // 检测一级标题(# 标题)- 跳过项目名称 if (line.startsWith('# ') && !line.includes('自动化分拣输送线')) { if (currentSection) { sections.push(currentSection); } currentSection = { title: line.replace('# ', ''), content: '' }; } // 检测二级标题(## 标题) else if (line.startsWith('## ')) { if (currentSection) { sections.push(currentSection); } currentSection = { title: line.replace('## ', ''), content: '' }; } // 普通内容行 else if (currentSection && line.trim() !== '') { if (currentSection.content) { currentSection.content += '\n'; } currentSection.content += line; } } // 添加最后一个section if (currentSection) { sections.push(currentSection); } return sections; } // 生成项目数据 const sections = parseMarkdownToSections(markdownContent); const clickableProjectData = { id: "clickable-1", name: "自动化分拣输送线的扫码分流、气缸拨臂与卡箱监测控制", unitName: "智能仓储系统监测", isClickable: true, content: { title: "自动化分拣输送线的扫码分流、气缸拨臂与卡箱监测控制", description: "某电商仓分拣线包含一条主输送线与一条侧向分流线。通过条码扫描器识别包裹目的地,当识别为需分流时,驱动气缸拨臂将包裹推入侧线,实现自动化分拣控制。", images: [], sections: sections } }; console.log('转换后的可点击项目数据:'); console.log(JSON.stringify(clickableProjectData, null, 2)); console.log('\n项目sections数量:', sections.length); sections.forEach((section, index) => { console.log(`Section ${index + 1}: ${section.title} (${section.content.length} 字符)`); });