const fs = require("fs");
const serverPath = require("./serverPath.js")
const pages = ["/index.html", "/blog/index.html", "/blog/reviews/index.html", "/project/index.html", "/board/index.html", "/board/tech/index.html", "/board/gen/index.html", "/board/films/index.html"];
const { header, footer} = 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)
	// Header
	let command = `sed -i 's|<div id="header">.*</div><!--header-->|<div id="header">${header}</div><!--header-->|'  ${page}`;

	exec(command, (error, stdout, stderr) => {
	  if (error) {
	    console.error(`Error: ${error.message}`);
	    return;
	  }
	  else {
		console.log(`Successfully added header to page`)
	  }
	});

	// Footer
	command = `sed -i 's|<div id="footer">.*</div><!--footer-->|<div id="footer">${footer}</div><!--footer-->|'  ${page}`;

	exec(command, (error, stdout, stderr) => {
	  if (error) {
	    console.error(`Error: ${error.message}`);
	    return;
	  }
	  else {
		console.log(`Successfully added footer to page`)
	  }
	});
}
