const fs = require("fs-extra");
const utils = require("../../src/services/utils.js");
const html = require("html");
const SRC_DIR = './src-build/docs-website';
const USER_GUIDE_DIR = './docs/user_guide';
const META_PATH = USER_GUIDE_DIR + '/!!!meta.json';
const WEB_TMP_DIR = './tmp/user_guide_web';
fs.copySync(USER_GUIDE_DIR, WEB_TMP_DIR);
const meta = JSON.parse(readFile(META_PATH));
const rootNoteMeta = meta.files[0];
const noteIdToMeta = {};
createNoteIdToMetaMapping(rootNoteMeta);
addNavigationAndStyle(rootNoteMeta, WEB_TMP_DIR);
fs.writeFileSync(WEB_TMP_DIR + '/main.js', readFile(SRC_DIR + "/main.js"));
fs.writeFileSync(WEB_TMP_DIR + '/main.css', readFile(SRC_DIR + "/main.css"));
fs.cpSync('libraries/ckeditor/ckeditor-content.css' ,WEB_TMP_DIR + '/ckeditor-content.css');
function addNavigationAndStyle(noteMeta, parentDirPath) {
const nav = createNavigation(rootNoteMeta, noteMeta);
if (noteMeta.dataFileName) {
const filePath = parentDirPath + "/" + noteMeta.dataFileName;
console.log(`Adding nav to ${filePath}`);
const content = readFile(filePath);
const depth = noteMeta.notePath.length - 1;
const updatedContent = content
.replaceAll("", `
`)
.replaceAll("