Skip to content

Instantly share code, notes, and snippets.

@Shwartz
Last active January 10, 2017 14:51
Show Gist options
  • Save Shwartz/815fd88e35312fd2844145089e788888 to your computer and use it in GitHub Desktop.
Save Shwartz/815fd88e35312fd2844145089e788888 to your computer and use it in GitHub Desktop.
gulp task to create index file with a list of all files - TOC
/*
* Utility to create index file with a list of all files - TOC
* */
gulp.task('create-toc', function () {
var fs = require('fs');
var fileList = '';
fs.readdir('pages/cats', function(err, files) {
files.forEach(function (file) {
fileList += '<li><a href="'+ file +'">'+ file +'</a></li>';
});
fs.writeFileSync('pages/cats/index.html', '<html><head></head><body><h3>Content</h3><ul>'+ fileList +'</ul></body></html>');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment