From aed389f9c9e15660ade5d81a8b41f6c219601c99 Mon Sep 17 00:00:00 2001 From: Michael Huang Date: Fri, 5 Aug 2016 21:26:49 -0700 Subject: [PATCH] Allow arbitrary extensions (not just .html files) --- index.js | 4 +++- .../custom-file-names/expected-output/foo.bar/index.html | 5 +++++ .../expected-output/foo/bar/custom_ext.liquid | 5 +++++ test/success-cases/custom-file-names/webpack.config.js | 4 +++- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/success-cases/custom-file-names/expected-output/foo.bar/index.html create mode 100644 test/success-cases/custom-file-names/expected-output/foo/bar/custom_ext.liquid diff --git a/index.js b/index.js index ee72fe6..b53f0f9 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,9 @@ StaticSiteGeneratorWebpackPlugin.prototype.apply = function(compiler) { renderPromises = self.outputPaths.map(function(outputPath) { var outputFileName = outputPath.replace(/^(\/|\\)/, ''); // Remove leading slashes for webpack-dev-server - if (!/\.(html?)$/i.test(outputFileName)) { + // If there is no extension, then assume it's a folder and add an index.html file + // (for a path like `/directory.with.dots/` then use `/directory.with.dots/index.html` ) + if (!/\.(\w+)$/i.test(outputFileName)) { outputFileName = path.join(outputFileName, 'index.html'); } diff --git a/test/success-cases/custom-file-names/expected-output/foo.bar/index.html b/test/success-cases/custom-file-names/expected-output/foo.bar/index.html new file mode 100644 index 0000000..7d6c2fb --- /dev/null +++ b/test/success-cases/custom-file-names/expected-output/foo.bar/index.html @@ -0,0 +1,5 @@ + + +

/foo.bar/index.html

+ + diff --git a/test/success-cases/custom-file-names/expected-output/foo/bar/custom_ext.liquid b/test/success-cases/custom-file-names/expected-output/foo/bar/custom_ext.liquid new file mode 100644 index 0000000..2bc0b67 --- /dev/null +++ b/test/success-cases/custom-file-names/expected-output/foo/bar/custom_ext.liquid @@ -0,0 +1,5 @@ + + +

/foo/bar/custom_ext.liquid

+ + diff --git a/test/success-cases/custom-file-names/webpack.config.js b/test/success-cases/custom-file-names/webpack.config.js index 215fe65..dc76b15 100644 --- a/test/success-cases/custom-file-names/webpack.config.js +++ b/test/success-cases/custom-file-names/webpack.config.js @@ -7,7 +7,9 @@ var template = ejs.compile(fs.readFileSync(__dirname + '/template.ejs', 'utf-8') var paths = [ '/custom.html', '/foo/custom.html', - '/foo/bar/custom.html' + '/foo/bar/custom.html', + '/foo/bar/custom_ext.liquid', + '/foo.bar/index.html', ]; module.exports = {