- Заменена группа из 9 пунктов Workflow в sidebar на одну ссылку - Обновлён concat-md.js: 9 файлов воркфлоу заменены на workflow.md
108 lines
3.2 KiB
JavaScript
108 lines
3.2 KiB
JavaScript
import path from "path";
|
||
import fs from "fs";
|
||
|
||
// Явный порядок файлов внутри каждого языка
|
||
const fileOrder = [
|
||
// index
|
||
"index.md",
|
||
// workflow
|
||
"workflow.md",
|
||
// basics
|
||
"basics/tech-stack.md",
|
||
"basics/architecture.md",
|
||
"basics/code-style.md",
|
||
"basics/naming.md",
|
||
"basics/documentation.md",
|
||
"basics/typing.md",
|
||
// applied
|
||
"applied/vscode.md",
|
||
"applied/project-structure.md",
|
||
"applied/components.md",
|
||
"applied/page-level.md",
|
||
"applied/templates-generation.md",
|
||
"applied/styles.md",
|
||
"applied/images-sprites.md",
|
||
"applied/svg-sprites.md",
|
||
"applied/video.md",
|
||
"applied/api.md",
|
||
"applied/stores.md",
|
||
"applied/hooks.md",
|
||
"applied/fonts.md",
|
||
"applied/localization.md",
|
||
];
|
||
|
||
// Удалить frontmatter из содержимого md-файла
|
||
const stripFrontmatter = (content) =>
|
||
content.replace(/^---[\s\S]*?---\n*/m, "");
|
||
|
||
// Сдвинуть уровень заголовков на 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");
|
||
};
|
||
|
||
// Собрать RULES.md с мета-якорями для каждого файла
|
||
const buildRules = (lang) => {
|
||
const srcDir = `./docs/${lang}`;
|
||
const outDir = `./generated/${lang}`;
|
||
const outFile = path.join(outDir, "RULES.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 = 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(`RULES.md (${lang}) создан: ${outFile}`);
|
||
};
|
||
|
||
// Собираем RULES.md для обоих языков
|
||
buildRules("ru");
|
||
buildRules("en");
|
||
|
||
// Генерируем README из index.md
|
||
const buildReadme = (lang, outFile) => {
|
||
const indexPath = `./docs/${lang}/index.md`;
|
||
|
||
if (!fs.existsSync(indexPath)) {
|
||
console.log(`Пропуск README (${lang}): ${indexPath} не найден`);
|
||
return;
|
||
}
|
||
|
||
const content = stripFrontmatter(fs.readFileSync(indexPath, "utf8"));
|
||
fs.writeFileSync(outFile, content, "utf8");
|
||
console.log(`${outFile} создан из ${indexPath}`);
|
||
};
|
||
|
||
buildReadme("en", "./README.md");
|
||
buildReadme("ru", "./README_RU.md");
|