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, "\\|"); pageTop = pageTop.replace(/'/g, "\\&\\#39;"); // Header let command = `sed -i 's#.*#${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, "\\|"); pageBottom = pageBottom.replace(/'/g, "\\&\\#39;"); command = `sed -i 's#.*#${pageBottom}#' ${page}`; exec(command, (error, stdout, stderr) => { if (error) { console.error(`Error: ${error.message}`); return; } else { console.log(`Successfully added footer to page`) } }); }