/* ========================================================================== AI Agent 脚手架项目学习 · 页面骨架生成器(一次性使用) 依据 tools/outline.json 生成 index.html、part-N.html 与 NN-slug.html 三类页面。 只写「页面外壳 + 标题 + 占位」,顶栏导航 / 侧栏目录 / 翻页 / 页脚 / 卡片 / 进度 全部交给 tools/build-nav.js 填充——两侧的自动区块标记保持原样,不要手改。 用法:node tools/gen-skeleton.js ========================================================================== */ "use strict"; const fs = require("fs"); const path = require("path"); const ROOT = path.resolve(__dirname, ".."); const PLAN = JSON.parse(fs.readFileSync(path.join(ROOT, "tools", "outline.json"), "utf8")); const S = PLAN.site; const PAD = (n) => String(n).padStart(2, "0"); const CHAPS = PLAN.parts.flatMap((p) => p.chapters); const TOTAL = CHAPS.length; const esc = (s) => String(s).replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); const stripNo = (t) => t.replace(/^\d+(\.\d+)*\s*/, ""); function head(title, desc, keywords) { return ` ${esc(title)}
${esc(S.name)}${esc(S.sub)}
`; } function tail() { return `
`; } /* ---------------------------- 章节页 ---------------------------- */ function chapterPage(part, c, num) { const secs = c.sections .map( (s) => `

${esc(s.title)}

本节正文待撰写:${esc(stripNo(s.title))}。

` ) .join("\n"); const leadTail = c.sections .slice(0, 3) .map((s) => stripNo(s.title)) .join("、"); return ( head(`第 ${num} 章 ${c.title} · ${S.name}`, c.desc, c.keywords) + `

${num}${esc(c.title)}

这一章解决什么:${esc(c.desc)} 读完这一章,你要能用自己的话讲清 ${c.sections.length} 个知识点${leadTail ? `,例如「${esc(leadTail)}」` : ""}, 并且能指回具体文件与函数。
${secs}

` + tail() ); } /* ---------------------------- 篇章页 ---------------------------- */ function partPage(p) { const first = CHAPS.indexOf(p.chapters[0]) + 1; const last = CHAPS.indexOf(p.chapters[p.chapters.length - 1]) + 1; const desc = `篇 ${p.no} ${p.name}:${p.note}`; return ( head(`篇 ${p.no} ${p.name} · ${S.name}`, desc, p.chapters.map((c) => c.title).join(",")) + `

本篇覆盖第 ${first}–${last} 章;各章正文与代码段待撰写。

` + tail() ); } /* ---------------------------- 学习地图 ---------------------------- */ function indexPage() { const secs = CHAPS.reduce((n, c) => n + c.sections.length, 0); return ( head(S.title, S.desc, "AI Agent,Go,Gin,ADK,MCP,脚手架,项目学习") + `

${esc(S.name)}:配置驱动的 Go 智能体脚手架

这套脚手架用三层配置(.env / application.yaml / agent YAML)驱动一条六节点装配链,把「模型 + 工具 + 工作流」 拼成可对话的 Agent,并通过 Gin 暴露四个业务接口。本学习站按「全景 → 前置 → 源码拆解 → 缺陷与演进 → 场景与面试 → 速查」 六篇 ${TOTAL} 章展开,每一条结论都指回具体文件与行号。

学习地图

六个篇章,从「能跑能演示」到「抽象成方法论」;共 ${TOTAL} 章 ${secs} 个小节。建议先读篇 0 建立地图,再按篇 2 的顺序追源码。

` + tail() ); } /* ---------------------------- 写盘 ---------------------------- */ const written = []; fs.writeFileSync(path.join(ROOT, "index.html"), indexPage(), "utf8"); written.push("index.html"); for (const p of PLAN.parts) { const file = `part-${p.no}.html`; fs.writeFileSync(path.join(ROOT, file), partPage(p), "utf8"); written.push(file); } for (const c of CHAPS) { const num = CHAPS.indexOf(c) + 1; const part = PLAN.parts.find((p) => p.chapters.includes(c)); fs.writeFileSync(path.join(ROOT, c.file), chapterPage(part, c, num), "utf8"); written.push(c.file); } console.log(`已生成 ${written.length} 个页面:索引 1、篇章 ${PLAN.parts.length}、章节 ${TOTAL}。`); console.log(`小节合计 ${CHAPS.reduce((n, c) => n + c.sections.length, 0)} 个。`); console.log("下一步:node tools/build-nav.js && node tools/check-pages.js --allow-empty");