import fs from "fs" import path from "path" const cwd = process.cwd() const readmePath = path.join(cwd, "README.md") const outputPath = path.join(cwd, "public", "about-content.json") const pkgPath = path.join(cwd, "package.json") if (!fs.existsSync(readmePath)) { console.error("README.md not found") process.exit(1) } const readmeContent = fs.readFileSync(readmePath, "utf-8") // 提取 README 的主要内容(跳过徽章部分) const lines = readmeContent.split("\n") let startIndex = 0 // 找到第一个非空行且不是徽章的行 for (let i = 0; i < lines.length; i++) { const line = lines[i].trim() // 跳过徽章行、空行、标题行 if (line && !line.startsWith("<") && !line.startsWith("[") && !line.startsWith("!")) { startIndex = i break } } // 提取主要内容 const mainContent = lines.slice(startIndex).join("\n") // 简单的 markdown 转 HTML(保留基本格式) function markdownToHtml(md) { return md .replace(/^### (.*$)/gim, "
$1")
.replace(/^- (.*$)/gim, "