From 71bf9554707d096dd367cd0227853106b2a5fad7 Mon Sep 17 00:00:00 2001 From: Mhykol Date: Mon, 10 Jun 2024 04:34:51 -0400 Subject: Added user generated titles --- app.js | 16 +++++++++---- source/readfile.js | 67 ++++++++++++++++-------------------------------------- 2 files changed, 32 insertions(+), 51 deletions(-) diff --git a/app.js b/app.js index 433d0b1..bb8e066 100644 --- a/app.js +++ b/app.js @@ -36,7 +36,12 @@ require('dotenv').config() // Handles the routes class App { constructor() { - this.readfile = new readfile({baseUrl: process.env.baseUrl, mime: mime}) + this.readfile = new readfile({ + baseUrl: process.env.baseUrl, + mime: mime, + header: 'header.html', + footer: 'footer.html' + }) this.controller = new Controller() } @@ -76,7 +81,10 @@ class App { if (this.path.string.endsWith('/') && this.path.string.length > 1) this.path.string = this.path.string.substring(0, this.path.string.length - 1) if (output.has(this.path.string)) { try { - output.get(this.path.string).then(output => res.send(this.readfile.GetMain(output.meta))) + output.get(this.path.string).then(output => { + console.log(output.meta) + res.send(this.readfile.GetMain(output.meta)) + }) } catch { res.send(this.readfile.GetMain(output.get(this.path.string))) } @@ -107,9 +115,9 @@ class App { this.readfile.Create(output.html).then(output => { const DOMPurify = createDOMPurify(new JSDOM('').window) const clean = DOMPurify.sanitize(output.layouts.header + output.layouts.data + output.layouts.footer, { - ADD_TAGS: ["iframe"], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling'] + ADD_TAGS: ['iframe'], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling'] }) - res.send(JSON.stringify({html: clean, css: object.css, js: object.js})) + res.send(JSON.stringify({title: object.title, html: clean, css: object.css, js: object.js})) }) }) } catch { diff --git a/source/readfile.js b/source/readfile.js index 7bb16a5..f93add4 100644 --- a/source/readfile.js +++ b/source/readfile.js @@ -19,36 +19,9 @@ class ReadFile { main: '', types: x.mime, layouts: { - header: ` - - `, - footer: ` - - ` + header: fs.readFileSync('./views/layouts/header.html', 'utf-8'), + loading: fs.readFileSync('./views/layouts/loading.html', 'utf-8'), + footer: fs.readFileSync('./views/layouts/footer.html', 'utf-8') } } for (const key in this.object.layouts) {this.object.layouts[key] = this.#RemoveSpaces(this.object.layouts[key])} @@ -58,46 +31,46 @@ class ReadFile { } GetMain(x) { - const data = {} + const data = { + header: '', + footer: ` + + + + + + + ` + } try { data.header = ` - Welcome to my website! + ${x.title} + + ${this.object.layouts.loading}
- `, - data.footer = ` -
- - - - ` } catch { data.header = ` - Welcome to my website! + Undefined + + ${this.object.layouts.loading}
` - data.footer = ` -
- - - - - ` } return this.#RemoveSpaces(data.header + data.footer) } -- cgit v1.2.3-70-g09d2