diff options
Diffstat (limited to 'source/blog.js')
| -rw-r--r-- | source/blog.js | 37 |
1 files changed, 22 insertions, 15 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, |
