diff --git a/bin/nodeppt b/bin/nodeppt index ddafe90e2..42f3d9eb9 100755 --- a/bin/nodeppt +++ b/bin/nodeppt @@ -34,15 +34,21 @@ program console.log(); }); +function assertPathWarn(){ + console.warn('The asset-path params will be ignored when output all files.'); +} + program .command('generate') .alias('release') .usage('[file_path] [save_path]') .description('export html file') .option('-a, --all [false]', 'output all style(include js,css) file', false) + .option('-p, --asset-path','set the relative path of assets(in website), ignored when -a is specified') .action(function (cmd, output, options) { var filename = ''; var shouldAll = false; + var path = ''; if (typeof output !== 'string') { options = output; output = undefined; @@ -50,17 +56,29 @@ program if (typeof cmd === 'string') { filename = cmd; shouldAll = options.all; + if (options.assetPath && shouldAll ) { + assertPathWarn(); + } else { + path = options.assetPath; + } } else if (typeof cmd === 'object') { shouldAll = cmd.all; output = cmd.output; + if (cmd.assetPath && shouldAll ) { + assertPathWarn(); + } else { + path = cmd.assetPath; + } } - nodePPT.generate(filename, output, shouldAll, ''); + + nodePPT.generate(filename, output, shouldAll, path || ''); }) .on('--help', function () { console.log(' Examples:'); console.log(); console.log(' nodeppt generate /markdown/path.md /output/path'); console.log(' nodeppt generate /markdown/path.md /output/path -a'); + console.log(' nodeppt generate /markdown/path.md /output/path -p ../lib/nodeppt'); console.log(); }); diff --git a/lib/generate.js b/lib/generate.js index 726b8f2d1..4f1152c76 100755 --- a/lib/generate.js +++ b/lib/generate.js @@ -113,6 +113,7 @@ function generate(filepath, outputDir, rDir) { //处理绝对路径的url function handlerHTML(html, rDir) { + rDir = rDir.replace(/\/$/,''); html = html.replace(/(src|href|url)([=|\(])(["'])\/\//gi, '$1$2$3<=PLACEHOLDER=>//') .replace(/(src|href|url)([=|\(])(["'])\//gi, '$1$2$3' + rDir + '/') .replace(/(src|href|url)([=|\(])(["'])<=PLACEHOLDER=>\//gi, '$1$2$3//')