const settings = require('./settings') const fs = require('fs') //TODO: make async module.exports = scanDirectory(settings.siteTitle, __dirname + settings.searchDir) function scanPages(dir, files){ var pages = {} for(i=files.length-1; i >= 0; i--){ var file, path, urlName, extention, fileName file = files[i] // full file name path = `${dir}/${file}` // full path to file fileName = file.split('.') extention = fileName.pop() // extention fileName = fileName.join('.') // filename without extention urlName = fileName.toLowerCase().replace(/\ /g, '-') // url friendly file name // skip files called index if(fileName == 'index'){ continue } // if directory if(fs.lstatSync(path).isDirectory()){ pages[urlName] = scanDirectory(file, path) continue } // is file pages[urlName] = { title: fileName, type: extention, file: path } } return pages } function scanDirectory(file, path){ var index var files = fs.readdirSync(path); if((index = files.indexOf('index.md')) != -1){ var fileName, extention fileName = files[index].split('.') extention = fileName.pop() fileName = fileName.join('.') index = { title: fileName, type: extention, file: `${path}/${files[index]}` } }else{ index = false } return { title: file, type: "directory", file: path, index: (index) ? index : { title: file, type: 'index', file: path }, subPages: scanPages(path, files) } }