Fix for empty page contents crashing parser

This commit is contained in:
NGPixel 2017-04-06 20:55:45 -04:00
parent d7a9b95850
commit 956d3aca08
3 changed files with 21 additions and 6 deletions

14
fuse.js
View File

@ -9,7 +9,7 @@
const _ = require('lodash')
const Promise = require('bluebird')
const colors = require('colors/safe')
const fs = Promise.promisifyAll(require('fs'))
const fs = Promise.promisifyAll(require('fs-extra'))
const fsbx = require('fuse-box')
const nodemon = require('nodemon')
const path = require('path')
@ -71,11 +71,13 @@ console.info(colors.white('└── ') + colors.green('Running global tasks...'
let globalTasks = Promise.mapSeries([
() => {
console.info(colors.white(' └── ') + colors.green('Copy + Minify ACE modes to assets...'))
return fs.readdirAsync('./node_modules/brace/mode').then(modeList => {
return Promise.map(modeList, mdFile => {
console.info(colors.white(' mode-' + mdFile))
let result = uglify.minify(path.join('./node_modules/brace/mode', mdFile), { output: { 'max_line_len': 1000000 } })
return fs.writeFileAsync(path.join('./assets/js/ace', 'mode-' + mdFile), result.code)
return fs.ensureDirAsync('./assets/js/ace').then(() => {
return fs.readdirAsync('./node_modules/brace/mode').then(modeList => {
return Promise.map(modeList, mdFile => {
console.info(colors.white(' mode-' + mdFile))
let result = uglify.minify(path.join('./node_modules/brace/mode', mdFile), { output: { 'max_line_len': 1000000 } })
return fs.writeFileAsync(path.join('./assets/js/ace', 'mode-' + mdFile), result.code)
})
})
})
}

View File

@ -285,6 +285,9 @@ module.exports = {
includeMarkdown: true,
includeParentInfo: true,
cache: true
}).catch(err => {
winston.error(err)
return err
}).then((pageData) => {
return {
entryPath,
@ -292,6 +295,9 @@ module.exports = {
parent: pageData.parent || {},
text: mark.removeMarkdown(pageData.markdown)
}
}).catch(err => {
winston.error(err)
return err
}).then((content) => {
return db.Entry.findOneAndUpdate({
_id: content.entryPath
@ -304,6 +310,9 @@ module.exports = {
new: true,
upsert: true
})
}).catch(err => {
winston.error(err)
return err
})
},

View File

@ -173,6 +173,10 @@ const parseContent = (content) => {
let output = mkdown.render(content)
let cr = cheerio.load(output)
if (cr.root().children().length < 1) {
return ''
}
// -> Check for empty first element
let firstElm = cr.root().children().first()[0]