32 lines
2.1 KiB
JavaScript
32 lines
2.1 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="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');
|
|
});
|
|
fs.appendFile(`${serverPath}/board/${boards[board]}/displayComments.js`,`let divText = document.getElementById("comments").innerHTML; newPageHTML=""; for (let comment = 0; comment < comments.length; comment++) { newPageHTML+=\`<b>\${comments[comment][0]}</b>: <i>\${comments[comment][1]}</i><br/>\`}; document.getElementById("comments").innerHTML = newPageHTML`, function (err) {
|
|
if (err) throw err;
|
|
console.log('Created displaycomments.js');
|
|
});
|
|
}
|
|
}
|