summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMhykol <mchaeldonald62@pm.me>2024-06-10 04:34:51 -0400
committerMhykol <mchaeldonald62@pm.me>2024-06-10 04:34:51 -0400
commit71bf9554707d096dd367cd0227853106b2a5fad7 (patch)
tree49bed80b513c1e4a02135f8f1520c996e6e7d9b9
parentacad4247d93e7a61b781924e5175664811bcf3e2 (diff)
Added user generated titles
-rw-r--r--app.js16
-rw-r--r--source/readfile.js67
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: `
- <section id='header'>
- <nav class='menulist' id='menu-list'>
- <a class='list' href='/'>Home</a>
- <a class='list' href='/about'>About</a>
- <a class='list' href='/blog'>Blog</a>
- <a class='list' href='https://git.fatalmatrix.xyz/'>Git Server</a>
- <div class='close' id='close'>
- <p>&#10005;</p>
- </div>
- </nav>
- <div class='menuIcon' id='menu-icon'>
- <div></div>
- <div></div>
- <div></div>
- </div>
- </section>
- `,
- footer: `
- <section id='footer'>
- <div class='copied'>
- <p>Copied to clipboard</p>
- </div>
- <div class='links'>
- <p>Email <a href='mailto:mchaeldonald62@pm.me'>mchaeldonald62@pm.me</a></p>
- <p>Monero <span class='footer-links'>89dARfwUGJNByHeir8bpCM4YJS2cTz58DNvu9fad1bpg7bfZs2H1QwtJpFghhJJatzRo8rnrE8AH5CAXbQHUpTp5FujsU1h</span></p>
- <p>Bitcoin <span class='footer-links'>bc1qplmr9wx7ahcna5zmwlhhl5zcgs8n5nuxp74apw</span></p>
- </div>
- </section>
- `
+ 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: `
+ </section>
+ <script src='/js/purify.js'></script>
+ <script src='/js/loading.js'></script>
+ <script src='/js/main.js'></script>
+ </body>
+ </html>
+ `
+ }
try {
data.header = `
<!DOCTYPE html>
<html lang='en'>
<head>
- <title>Welcome to my website!</title>
+ <title>${x.title}</title>
<meta name='description' content='${x.description}'>
<meta name='keywords' content='${x.keywords}'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
+ <link rel='stylesheet' type='text/css' href='/css/loading.css'>
</head>
<body>
+ ${this.object.layouts.loading}
<section id='main'>
- `,
- data.footer = `
- </section>
- <script src='/js/purify.js'></script>
- <script src='/js/main.js'></script>
- </body>
- </html>
`
} catch {
data.header = `
<html>
<head>
- <title>Welcome to my website!</title>
+ <title>Undefined</title>
<meta name='description' content=''>
<meta name='keywords' content=''>
<meta name='viewport' content='width=device-width, initial-scale=1'>
+ <link rel='stylesheet' type='text/css' href='/css/loading.css'>
</head>
<body>
+ ${this.object.layouts.loading}
<section id='main'>
`
- data.footer = `
- </section>
- <script src='/js/purify.js'></script>
- <script src='/js/main.js'></script>
- </body>
- </html>
- `
}
return this.#RemoveSpaces(data.header + data.footer)
}