A Gulp plugin to rename non-index files to indices within matching subdirectories.
This plugin can be used to enable serving a static website with clean, extensionless URLs (e.g. https://www.example.com/example-page/
) without needing to configure the web server to rewrite URLs, by moving generated files to index files within a matching subdirectory.
For example, given the following source files:
pages/index.html
pages/about.html
pages/contact.html
The following files will be output:
dist/index.html
dist/about/index.html
dist/contact/index.html
Import the indexDirs
function and add it to a Gulp stream.
import indexDirs from '@averay/gulp-index-dirs';
gulp
.src('...')
.pipe(/* Apply plugins */)
.pipe(indexDirs())
.pipe(gulp.dest('...'));
The function takes a single optional argument of the extensionless index file name, defaulting to index
:
// ...
.pipe(indexDirs('default')) // Will result in e.g. default.html