|
/* Building an index of elements : pages,post, … |
|
|
|
|
|
https://medium.com/@bushwazi/super-simple-static-site-generation-with-node-jade-gulp-and-json-9ded83508fa6#.hvt5p0bqm |
|
https://github.com/Bushwazi/static-site-generation-with-jade-gulp/blob/master/_src/gulpfile.js |
|
|
|
|
|
*/ |
|
// https://www.npmjs.com/package/gulp-gray-matter |
|
// https://www.npmjs.com/package/gray-matter#options |
|
var frontmatter = require('gulp-gray-matter') |
|
var fsRecurs = require('fs-readdir-recursive') |
|
var matter = require('gray-matter'); |
|
var util = require('util') |
|
var pageDir = './src/pages/' |
|
var summaryJSON = new Object() |
|
|
|
function buildIndex(baseDir,objectType){ |
|
var counter = 0 ; |
|
files = fsRecurs(baseDir) |
|
files.map(function(url,ind,arr){ |
|
//current = fs.readFileSync(pageDir + url, 'utf-8') |
|
|
|
file = matter.read(baseDir + url) |
|
|
|
if(path.basename(file.path,'.md') === 'index') |
|
url = '/' |
|
else |
|
url = path.dirname(file.path).replace(baseDir, '') + '/' + path.basename(file.path,'.md') + '.html' |
|
|
|
//console.log(path.dirname(file.path).replace(pageDir, '')) |
|
|
|
summaryJSON[objectType + '-' + counter] = { |
|
'path': file.path, |
|
'url': url, |
|
'title': file.data.title, |
|
'description': file.data.description |
|
} |
|
|
|
counter++; |
|
}); |
|
|
|
return summaryJSON; |
|
} |
|
|
|
|
|
console.log(buildIndex(pageDir,'page')) |