diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/blog.js | 37 | ||||
| -rw-r--r-- | source/readfile.js | 2 |
2 files changed, 23 insertions, 16 deletions
diff --git a/source/blog.js b/source/blog.js index 57735b7..8e0922f 100644 --- a/source/blog.js +++ b/source/blog.js @@ -1,7 +1,11 @@ const fs = require('fs') const path = require('path') const markdownit = require('markdown-it') -const md = markdownit() +const md = markdownit({ + typographer: { + whitespace: 'all' + } +}) const logger = require('./logger')() // Parse markdown @@ -20,27 +24,30 @@ class Blog { this.blog = new Map() files.forEach(file => { - this.blog.set(file.replace('.md', ''), fs.readFileSync(path.resolve(`./blog/${file}`), 'utf-8', (err, data) => { - if (err) { - logger.Error(err) - return - } - return data - })) + try { + this.blog.set(file.replace('.md', ''), fs.readFileSync(path.resolve(`./blog/${file}`), 'utf-8', (err, data) => { + if (err) { + logger.Error(err) + return + } + return data + })) + } catch (err) { + logger.Error(err) + } }) this.blog.forEach((value, key) => { - this.regex = /# (.*)\nDate: (.*)\n---(.*?)---/s - this.match = value.match(this.regex) + const regex = /# (.*)\nDate: (.*)\n---(.*?)---/s + const match = value.match(regex) - if (this.match) { - const [, title, date, description] = this.match - this.object = { + if (match) { + const [, title, date, description] = match + this.blog.set(key, { title: title, date: new Date(date), short: description, body: md.render(value) - } - this.blog.set(key, this.object) + }) } else { this.blog.set(key, { title: undefined, diff --git a/source/readfile.js b/source/readfile.js index c3970f6..1f332d0 100644 --- a/source/readfile.js +++ b/source/readfile.js @@ -102,7 +102,7 @@ class ReadFile { } async #GetFileType(x) {return this.object.types[path.extname('./assets/'+ x[1] + '/' + x[2]).slice(1)] || 'text/plain'} #Build() {return fs.readFileSync('./views/layouts/header.html', 'utf-8') + fs.readFileSync('./views/layouts/footer.html', 'utf-8')} - #RemoveSpaces(x) {return x.replace(/(\n)\s+/g, '$1')} + #RemoveSpaces(x) {return x.replace(/^(\n)\s+/gm, '$1')} } module.exports = ReadFile |
