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 _ = require('lodash')
const Promise = require('bluebird') const Promise = require('bluebird')
const colors = require('colors/safe') const colors = require('colors/safe')
const fs = Promise.promisifyAll(require('fs')) const fs = Promise.promisifyAll(require('fs-extra'))
const fsbx = require('fuse-box') const fsbx = require('fuse-box')
const nodemon = require('nodemon') const nodemon = require('nodemon')
const path = require('path') const path = require('path')
@ -71,11 +71,13 @@ console.info(colors.white('└── ') + colors.green('Running global tasks...'
let globalTasks = Promise.mapSeries([ let globalTasks = Promise.mapSeries([
() => { () => {
console.info(colors.white(' └── ') + colors.green('Copy + Minify ACE modes to assets...')) console.info(colors.white(' └── ') + colors.green('Copy + Minify ACE modes to assets...'))
return fs.readdirAsync('./node_modules/brace/mode').then(modeList => { return fs.ensureDirAsync('./assets/js/ace').then(() => {
return Promise.map(modeList, mdFile => { return fs.readdirAsync('./node_modules/brace/mode').then(modeList => {
console.info(colors.white(' mode-' + mdFile)) return Promise.map(modeList, mdFile => {
let result = uglify.minify(path.join('./node_modules/brace/mode', mdFile), { output: { 'max_line_len': 1000000 } }) console.info(colors.white(' mode-' + mdFile))
return fs.writeFileAsync(path.join('./assets/js/ace', 'mode-' + mdFile), result.code) 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, includeMarkdown: true,
includeParentInfo: true, includeParentInfo: true,
cache: true cache: true
}).catch(err => {
winston.error(err)
return err
}).then((pageData) => { }).then((pageData) => {
return { return {
entryPath, entryPath,
@ -292,6 +295,9 @@ module.exports = {
parent: pageData.parent || {}, parent: pageData.parent || {},
text: mark.removeMarkdown(pageData.markdown) text: mark.removeMarkdown(pageData.markdown)
} }
}).catch(err => {
winston.error(err)
return err
}).then((content) => { }).then((content) => {
return db.Entry.findOneAndUpdate({ return db.Entry.findOneAndUpdate({
_id: content.entryPath _id: content.entryPath
@ -304,6 +310,9 @@ module.exports = {
new: true, new: true,
upsert: 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 output = mkdown.render(content)
let cr = cheerio.load(output) let cr = cheerio.load(output)
if (cr.root().children().length < 1) {
return ''
}
// -> Check for empty first element // -> Check for empty first element
let firstElm = cr.root().children().first()[0] let firstElm = cr.root().children().first()[0]