htdocs/node/template.js

46 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

const fs = require("fs");
const serverPath = require("./serverPath.js")
2024-12-17 19:11:08 +01:00
//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"];
2024-12-27 03:17:48 +01:00
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"]
2024-12-17 19:11:08 +01:00
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)
2024-12-17 19:11:08 +01:00
pageTop = pageTop.replace(/\n/g, '');
pageTop = pageTop.replace(/\\/g, '\\');
pageTop = pageTop.replace(/\|/g, "\\&vert;");
pageTop = pageTop.replace(/'/g, "\\&\\#39;");
// Header
2024-12-27 03:17:48 +01:00
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
2024-12-17 19:11:08 +01:00
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`)
}
});
}