const fs = require('fs') const path = require('path') const logger = require('./logger')() const template = require('../template/template') const routesConfig = require('../config/routes') class BuildPages { constructor(x) { this.newTemplate = new Map() this.template = template({baseURL: x.baseURL}) this.pages = typeof this.GetAllPages() !== 'undefined' ? this.GetAllPages() : new Map() this.path = [] this.pages.forEach((value, key) => { this.path.push(key) }) this.routes = typeof x.routes !== 'undefined' ? x.routes : new Map() this.#AddTemplate({ name: 'start', template: ` ` }) this.html = { start: ` `, end: ` ` } } GetSitemap() {return this.path} Build(pageData) { const split = pageData.path.split('/') const string = `/${split[1]}` if (false) { } else if (this.pages.has(string)) { if (split[2] !== undefined && split[2] !== '') { const newPath = `/${split[1]}/${split[2]}` } else { const pages = this.pages.get(string) const data = pages (pageData) this.map = new Map() for (let i = 0; i < data.page.length; i++) { this.object = {} this.object.data = data.page[i] this.object.name = this.object.data.name if (pageData.path === '/') { if (this.object.name === 'index') { this.data = this.object.data() this.output = { html: this.data.html, css: this.data.css, js: this.data.js } this.output.js.push('loading.js') return this.output } } else { this.data = this.object.data() this.output = { html: this.data.html, css: this.data.css, js: this.data.js } this.output.js.push('loading.js') return this.output } } } } else { // ! 404 Not Found const notFound = this.template.NotFound() this.output = { html: { header: this.template.Header(), main: notFound.html, footer: this.template.Footer() }, css: [], js: ['loading.js'], pages: this.pages } notFound.css.forEach(file => this.output.css.push(file)) notFound.js.forEach(file => this.output.js.push(file)) return this.output } return false } Template(pageData) { const split = pageData.path.split('/') const string = `/${split[1]}` if (this.routes.has(pageData.path)) { } else if (this.pages.has(string)) { if (split[2] !== undefined && split[2] !== '') { } } const html = { start: ` `, head: `