htdocs/node/makeboards.js

32 lines
2.1 KiB
JavaScript
Raw Normal View History

2024-11-15 22:16:58 +01:00
const serverPath = require("./serverPath.js")
const boards = require(serverPath+"/board/boards.js");
2024-10-31 14:52:17 +01:00
const fs = require("fs");
2024-11-15 22:16:58 +01:00
const { pageTop, pageBottom } = require(serverPath+"/html.js")
2024-10-31 14:52:17 +01:00
console.log(boards);
for (let board = 0; board < boards.length; board++) {
console.log(boards[board]);
2024-11-15 22:16:58 +01:00
let boardPath = `${serverPath}/board/${boards[board]}`;
2024-10-31 14:52:17 +01:00
if (fs.existsSync(boardPath)) {
console.log(`Directory /${boards[board]}/ exists`)
} else {
console.log(`Directory /${boards[board]}/ doesn't exist... Creating`)
fs.mkdirSync(boardPath);
2024-11-15 22:16:58 +01:00
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');
});
2024-10-31 14:52:17 +01:00
}
}