Files
jiu/web/_data/docs.js
T
wangjia 471b980179 refactor(web): 营销站重构为 Eleventy SSG,内容迁移至 Markdown
- 引入 Eleventy 静态站点生成器,页面统一使用 Nunjucks 模板
- base.njk 提供公共 nav / footer / CSS,消除三个页面间的重复代码
- 抽取 color.css(设计 token)+ style.css(公共组件 + utility 类)
- index.njk:首页迁移,用 utility class 替换大量页面私有 CSS
- download.njk:下载页重构,版本号/更新日志从 CHANGELOG.md 构建时解析,OS 自动识别
- docs.njk:文档页重构,12 章内容从 web/content/docs.md 构建时渲染,三列布局保留
- docs.css 单独提取,docs 专有样式不污染公共 CSS
- 内容面向非技术用户重写,去除技术术语和内部路径引用

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 12:24:14 +08:00

52 lines
1.4 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const md = require('markdown-it')({ html: false, breaks: false, linkify: false });
const TOC_GROUPS = [
{ group: '快速开始', nums: [1, 2, 3] },
{ group: '业务操作', nums: [4, 5, 6, 7, 8, 9] },
{ group: '基础设置', nums: [10, 11, 12] },
];
module.exports = function() {
const raw = fs.readFileSync(path.join(__dirname, '../content/docs.md'), 'utf8');
const lines = raw.split('\n');
// Split into chapters by "## {n}. {title}" headings
const chapters = [];
let current = null;
for (const line of lines) {
const match = line.match(/^## (\d+)\. (.+)/);
if (match) {
if (current) chapters.push(current);
const num = parseInt(match[1], 10);
current = { num, id: 'ch-' + num, title: match[2].trim(), bodyLines: [] };
} else if (current) {
current.bodyLines.push(line);
}
}
if (current) chapters.push(current);
// Render each chapter's body to HTML
const rendered = chapters.map(ch => ({
num: ch.num,
id: ch.id,
title: ch.title,
html: md.render(ch.bodyLines.join('\n')),
}));
// Build TOC
const chapterMap = {};
rendered.forEach(ch => { chapterMap[ch.num] = ch; });
const toc = TOC_GROUPS.map(g => ({
group: g.group,
items: g.nums
.filter(n => chapterMap[n])
.map(n => ({ id: chapterMap[n].id, num: n, title: chapterMap[n].title })),
}));
return { toc, chapters: rendered };
};