Browse Source

Fix for empty page contents crashing parser

pull/73/head
NGPixel 7 years ago
parent
commit
956d3aca08
3 changed files with 21 additions and 6 deletions
  1. 14
      fuse.js
  2. 9
      libs/entries.js
  3. 4
      libs/markdown.js

14
fuse.js

@ -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 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)
})
}) })
}) })
} }

9
libs/entries.js

@ -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
}) })
}, },

4
libs/markdown.js

@ -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]

Loading…
Cancel
Save