diff --git a/lib/fix_html.js b/lib/fix_html.js index 89ba555..abcdbd6 100644 --- a/lib/fix_html.js +++ b/lib/fix_html.js @@ -5,6 +5,7 @@ const slugify = require('slugify') const resolve = require('path').resolve const dirname = require('path').dirname const relative = require('path').relative +const fs = require('fs') /** * Internal: Performs in-place HTML filters (such as fixing URLs). @@ -61,7 +62,31 @@ function fixReferences ($, fname, sources, files, page) { // Ensure that it's available. if (!sources[target]) { - throw new Error(`${base}: Unknown reference '${origUrl}'`) + + // copy images to dist + if ($this[0].name == 'img') { + + try { + let img = fs.readFileSync(cwd+'/'+target) + + // metalsmith will write the image + files[target] = { + contents: img, + filename: target + } + + // change to absolute URL + $this.attr(attr, '/'+target) + + } catch (err) { + console.warn(`${base}: Unknown reference '${origUrl}'`) + } + + } else { + console.warn(`${base}: Unknown reference '${origUrl}'`) + } + + return; } // Relativize that absolute URL. diff --git a/lib/ms.js b/lib/ms.js index 6d036f4..d160af5 100644 --- a/lib/ms.js +++ b/lib/ms.js @@ -23,6 +23,10 @@ function docpress (cwd, options) { .metadata(meta) .ignore('node_modules') .ignore(`!**/{${meta.docs}{,/**/*},*.md}`) + + if (Array.isArray(meta.ignore)) { + meta.ignore.forEach(str=>app.ignore(str)) + } if (Array.isArray(meta.ignore)) { meta.ignore.forEach(str => app.ignore(str))