htdocs/node/makeboards.js
2024-11-19 17:07:11 +00:00

28 lines
1.6 KiB
JavaScript

const serverPath = require("./serverPath.js")
const boards = require(serverPath+"/board/boards.js");
const fs = require("fs");
const { pageTop, pageBottom } = require(serverPath+"/html.js")
console.log(boards);
for (let board = 0; board < boards.length; board++) {
console.log(boards[board]);
let boardPath = `${serverPath}/board/${boards[board]}`;
if (fs.existsSync(boardPath)) {
console.log(`Directory /${boards[board]}/ exists`)
} else {
console.log(`Directory /${boards[board]}/ doesn't exist... Creating`)
fs.mkdirSync(boardPath);
fs.appendFile(`${serverPath}/board/${boards[board]}/index.html`,`<!DOCTYPE html><div id="header"></div><!--header--><div id="main"><div id="comments" class="${boards[board]}"></div><form action="/board/submit-comment" id="commentForm" method="post"><input name="name" class="form-control" id="name" placeholder="Enter your name"><br/><input height="40px" name="comment" class="form-control input-comment" id="comment" placeholder="Enter your Comment..."><input type="hidden" name="pageID" value="${boards[board]}"><button type="submit">Submit</button></form></div><!--main--><div id="footer"></div><!--footer--><script src="comments-database.js"></script><script src="/board/displayComments.js"></script>`, function (err) {
if (err) throw err;
console.log('Created page');
});
fs.appendFile(`${serverPath}/board/${boards[board]}/comments-database.js`,`let comments = [["ADMIN","welcome to the ${boards[board]} board"]]; if (typeof module != "undefined" && module.exports) { module.exports = comments; }`, function (err) {
if (err) throw err;
console.log('Created comments array');
});
}
}