htdocs/node/template.js
2024-12-27 02:17:48 +00:00

46 lines
1.6 KiB
JavaScript
Executable File

const fs = require("fs");
const serverPath = require("./serverPath.js")
//const pages = ["/index.html", "/blogs/index.html", "/blogs/reviews/index.html", "/board/index.html", "/board/tech/index.html", "/board/gen/index.html", "/board/films/index.html", "/board/maths/index.html","/maths/index.html"];
const pages = ["/index.html", "/blogs/index.html", "/board/index.html", "/board/test/index.html", "/board/tech/index.html", "/board/gen/index.html", "/board/films/index.html", "/board/maths/index.html"]
let { pageTop, pageBottom } = require(serverPath+"/html.js")
const { exec } = require('child_process');
for (let x = 0; x < pages.length; x++) {
console.log(x)
page = serverPath + pages[x]
console.log("editing", page)
pageTop = pageTop.replace(/\n/g, '');
pageTop = pageTop.replace(/\\/g, '\\');
pageTop = pageTop.replace(/\|/g, "\\&vert;");
pageTop = pageTop.replace(/'/g, "\\&\\#39;");
// Header
let command = `sed -i 's#.*<body>#${pageTop}#' ${page}`;
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
else {
console.log(`Successfully added header to page`)
}
});
// Footer
pageBottom = pageBottom.replace(/\n/g, '');
pageBottom = pageBottom.replace(/\\/g, '\\');
pageBottom = pageBottom.replace(/\|/g, "\\&vert;");
pageBottom = pageBottom.replace(/'/g, "\\&\\#39;");
command = `sed -i 's#</body>.*#</body>${pageBottom}#' ${page}`;
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
else {
console.log(`Successfully added footer to page`)
}
});
}