-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean_topmenu.js
More file actions
39 lines (33 loc) · 1.19 KB
/
Copy pathclean_topmenu.js
File metadata and controls
39 lines (33 loc) · 1.19 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
32
33
34
35
36
37
38
39
const fs = require("fs");
const path = require("path");
function walk(dir, callback) {
if (!fs.existsSync(dir)) return;
fs.readdirSync(dir).forEach((f) => {
let dirPath = path.join(dir, f);
if (fs.statSync(dirPath).isDirectory()) {
walk(dirPath, callback);
} else if (f.endsWith(".ejs") || f.endsWith(".html")) {
callback(dirPath);
}
});
}
walk(path.join(__dirname, "views"), (filePath) => {
let content = fs.readFileSync(filePath, "utf8");
let original = content;
// Remove topMenu includes (handling multiple formats and newlines inside EJS tags)
content = content.replace(
/<%-?\s*include\(['"`]\.\/partials\/topMenu\.ejs['"`][\s\S]*?%>\s*/g,
""
);
// Remove the old topMenu script tag from footer
content = content.replace(/<script src="\/js\/topMenu\.js[^>]*><\/script>\s*/g, "");
// Remove mt-16 class globally (accounting for surrounding spaces/quotes)
content = content.replace(/ mt-16 /g, " ");
content = content.replace(/mt-16 /g, "");
content = content.replace(/ mt-16"/g, '"');
content = content.replace(/mt-16"/g, '"');
if (content !== original) {
fs.writeFileSync(filePath, content);
console.log("Cleaned:", filePath);
}
});