diff --git a/lib/options.js b/lib/options.js index e94e0f4..09837b4 100644 --- a/lib/options.js +++ b/lib/options.js @@ -61,14 +61,14 @@ function parseThemeArg(theme) { } } -function parseScriptsArg(scripts) { - return (typeof scripts === 'string' ? scripts.split(',') : []).map(script => path.join('scripts', script)); +function parseAssetsArg(assets) { + return (typeof assets === 'string' ? assets.split(',') : []).map(asset => `assets/${asset}`); } -function parseScriptsPath(scripts) { - return (typeof scripts === 'string' ? scripts.split(',') : []).map(script => ({ - path: path.resolve(process.cwd(), script), - name: script +function parseAssetsPath(assets) { + return (typeof assets === 'string' ? assets.split(',') : []).map(asset => ({ + path: path.resolve(process.cwd(), asset), + name: asset })); } @@ -101,10 +101,10 @@ function parseOptions(args) { if(_.has(args, 'args.0')) _.extend(options, parsePath(args.args[0])); options.themePath = parseThemeArg(args.theme || defaults.theme); - options.scriptPaths = parseScriptsArg(args.scripts); - options.scriptSources = parseScriptsPath(args.scripts); - options.cssPaths = parseScriptsArg(args.css); - options.cssSources = parseScriptsPath(args.css); + options.scriptPaths = parseAssetsArg(args.scripts); + options.scriptSources = parseAssetsPath(args.scripts); + options.cssPaths = parseAssetsArg(args.css); + options.cssSources = parseAssetsPath(args.css); options.title = args.title || defaults.title; options.separator = args.separator || defaults.separator; options.verticalSeparator = args.verticalSeparator || defaults.verticalSeparator; diff --git a/lib/serve.js b/lib/serve.js index 406eb82..8003da3 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -19,8 +19,8 @@ function updatePathOptions(req, res, next) { next(); } -function getScript(req, res) { - res.sendFile(path.resolve(process.cwd(), req.url.replace(/^\/scripts\//, ''))); +function getAsset(req, res) { + res.sendFile(path.resolve(process.cwd(), req.url.replace(/^\/assets\//, ''))); } module.exports = function startServer(options, cb) { @@ -44,7 +44,7 @@ module.exports = function startServer(options, cb) { app.get('/', updatePathOptions, render.renderMarkdownFileListing); app.get(/(\w+\.md)$/, updatePathOptions, render.renderMarkdownAsSlides); - app.get('/scripts/*', getScript); + app.get('/assets/*', getAsset); app.get('/*', staticDir(process.cwd())); const server = app.listen(options.port); diff --git a/lib/static.js b/lib/static.js index 567d53d..751ad2b 100644 --- a/lib/static.js +++ b/lib/static.js @@ -9,6 +9,7 @@ module.exports = function renderStaticMarkup(options) { const staticPath = options.static === true ? '_static' : options.static; const targetPath = path.resolve(process.cwd(), staticPath); + const assetsDir = path.join(targetPath, 'assets'); const awaits = ['css', 'js', 'plugin', 'lib'].map(dir => fs.copyAsync(path.join(options.revealBasePath, dir), path.join(targetPath, dir))); @@ -22,17 +23,15 @@ module.exports = function renderStaticMarkup(options) { awaits.push(highlightAwait); if(!_.isEmpty(options.scripts)) { - const scriptsDir = path.join(targetPath, 'scripts'); - fs.ensureDirSync(scriptsDir); - const scriptAwaits = options.scriptSources.map(scriptFile => fs.copyAsync(scriptFile.path, path.join(scriptsDir, scriptFile.name))); - awaits.concat(scriptAwaits); + fs.ensureDirSync(assetsDir); + const assetAwaits = options.scriptSources.map(asset => fs.copyAsync(asset.path, path.join(assetsDir, asset.name))); + awaits.concat(assetAwaits); } if(!_.isEmpty(options.css)) { - const scriptsDir = path.join(targetPath, 'scripts'); - fs.ensureDirSync(scriptsDir); - const scriptAwaits = options.cssSources.map(scriptFile => fs.copyAsync(scriptFile.path, path.join(scriptsDir, scriptFile.name))); - awaits.concat(scriptAwaits); + fs.ensureDirSync(assetsDir); + const assetAwaits = options.cssSources.map(asset => fs.copyAsync(asset.path, path.join(assetsDir, asset.name))); + awaits.concat(assetAwaits); } Promise.all(awaits).then(() => console.log(`Wrote static site to ${targetPath}`)).catch(console.error); diff --git a/test/render.spec.js b/test/render.spec.js index d8f1928..5ce8276 100644 --- a/test/render.spec.js +++ b/test/render.spec.js @@ -25,15 +25,15 @@ describe('render', () => { it('should render custom scripts', () => { const actual = render.render('# header', {scripts: 'custom.js,also.js'}); - expect(actual).toInclude(''); - expect(actual).toInclude(''); + expect(actual).toInclude(''); + expect(actual).toInclude(''); }); it('should render custom css after theme', () => { const actual = render.render('# header', {css: 'style1.css,style2.css'}); const themeLink = ''; - const style1Link = ''; - const style2Link = ''; + const style1Link = ''; + const style2Link = ''; expect(actual).toInclude(themeLink); expect(actual).toInclude(style1Link); expect(actual).toInclude(style2Link);