forked from alexeykadochnik0v/js--pro
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadd-separators.js
More file actions
31 lines (23 loc) · 1.21 KB
/
add-separators.js
File metadata and controls
31 lines (23 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const fs = require("fs");
const path = require("path");
const lessonsDir = path.join(__dirname, "lessons");
const lessonDirs = fs
.readdirSync(lessonsDir)
.filter((dir) => dir.startsWith("lesson"));
lessonDirs.forEach((lessonDir) => {
const lessonPath = path.join(lessonsDir, lessonDir, "lesson.md");
if (fs.existsSync(lessonPath)) {
let content = fs.readFileSync(lessonPath, "utf8");
// Добавляем горизонтальные разделители между основными разделами (## заголовки)
content = content.replace(/\n## /g, "\n\n<!-- s -->\n\n## ");
// Добавляем вертикальные разделители между подразделами (### заголовки)
content = content.replace(/\n### /g, "\n\n<!-- v -->\n\n### ");
// Убираем лишний разделитель в начале файла, если он есть
content = content.replace(/^(---[\s\S]*?---\n\n)(<!-- s -->\n\n)/, "$1");
fs.writeFileSync(lessonPath, content);
console.log(`Added separators to ${lessonDir}/lesson.md`);
} else {
console.log(`File ${lessonPath} does not exist`);
}
});
console.log("Separators added to all lesson files");