Files
slm-design/concat-md.js
S.Gromov 23287ca5b0 chore: переименовать RULES.md в ARCHITECTURE.md и контейнер
- RULES.md переименован в ARCHITECTURE.md в concat-md.js
- обновлены ссылки в index.md, README.md, .gitignore
- контейнер в CI переименован из nextjs-style-guide в slm-design
2026-04-19 00:52:10 +03:00

77 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import path from "path";
import fs from "fs";
// Явный порядок файлов внутри каждого языка
const fileOrder = [
"index.md",
// reference
"reference/layers.md",
"reference/modules.md",
"reference/segments.md",
];
// Удалить frontmatter из содержимого md-файла
const stripFrontmatter = (content) =>
content.replace(/^---[\s\S]*?---\n*/m, "");
// Удалить блоки между маркерами <!-- rules-link --> и <!-- /rules-link -->
const stripRulesLink = (content) =>
content.replace(/<!-- rules-link -->[\s\S]*?<!-- \/rules-link -->\n*/g, "");
// Сдвинуть уровень заголовков на 1 вниз (h1→h2, h2→h3, ...)
// Не трогает заголовки внутри блоков кода
const shiftHeadings = (content) => {
const lines = content.split("\n");
let inCodeBlock = false;
return lines
.map((line) => {
if (line.startsWith("```")) inCodeBlock = !inCodeBlock;
if (inCodeBlock) return line;
if (/^#{1,5}\s/.test(line)) return "#" + line;
return line;
})
.join("\n");
};
// Собрать ARCHITECTURE.md с мета-якорями для каждого файла
const buildRules = (lang) => {
const srcDir = `./docs/${lang}`;
const outDir = `./generated/${lang}`;
const outFile = path.join(outDir, "ARCHITECTURE.md");
if (!fs.existsSync(srcDir)) {
console.log(`Пропуск ${lang}: папка ${srcDir} не найдена`);
return;
}
fs.mkdirSync(outDir, { recursive: true });
const parts = [];
for (const file of fileOrder) {
const filePath = path.join(srcDir, file);
if (!fs.existsSync(filePath)) continue;
const raw = fs.readFileSync(filePath, "utf8");
const content = stripRulesLink(stripFrontmatter(raw)).trim();
if (!content) continue;
// Мета-якорь: путь VitePress без расширения
const route = "/" + file.replace(/\.md$/, "");
// index.md остаётся без сдвига (его h1 — главный заголовок документа)
const processed = file === "index.md" ? content : shiftHeadings(content);
parts.push(`<!-- ${route} -->\n${processed}`);
}
fs.writeFileSync(outFile, parts.join("\n\n"), "utf8");
console.log(`ARCHITECTURE.md (${lang}) создан: ${outFile}`);
};
// Собираем ARCHITECTURE.md для обоих языков
buildRules("ru");
buildRules("en");