htdocs/node/makeboards.js

39 lines
1.6 KiB
JavaScript
Raw Permalink 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-12-15 21:09:42 +01:00
const { exec } = require("child_process");
2024-10-31 14:52:17 +01:00
console.log(boards);
for (let board = 0; board < boards.length; board++) {
2024-12-15 21:09:42 +01:00
let boardPath = `${serverPath}/board/${boards[board]}/index.html`;
2024-10-31 14:52:17 +01:00
2024-12-15 21:09:42 +01:00
fs.readFile(boardPath, (err, data) => {
if (err) {
console.log(`File /${boards[board]}/index.html doesn't exist... Creating`)
2024-12-27 03:17:48 +01:00
fs.writeFile(`${boardPath}`,`<body><form action="/board/submit-comment" id="commentForm" method="post"><input name="name" class="form-control" id="name" placeholder="Enter your name"><br/><textarea height="40px" name="comment" class="form-control input-comment" id="comment" placeholder="Enter your Comment..."></textarea><input type="hidden" name="pageID" value="${boards[board]}"><button type="submit">Submit</button></form><div id="comments" class="${boards[board]}" style="word-wrap: break-word"></div><!--comments--></div></body>`, function (err) {
2024-12-15 21:09:42 +01:00
if (err) throw err;
console.log('Created page');
});
exec('node write_comments.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
console.log(`Child script output: ${stdout}`);
});
exec('node template.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
console.log(`Child script output: ${stdout}`);
});
};
if (!err && data) {
console.log(`File exists: ${boards[board]}`)
}
});
2024-10-31 14:52:17 +01:00
}