add notes

This commit is contained in:
Mats van Reenen
2020-07-27 20:09:20 +02:00
parent 7b6806753d
commit 2cc2606967

View File

@@ -1,9 +1,22 @@
const settings = require('./settings') const settings = require('./settings')
const fs = require('fs') const fs = require('fs')
//TODO: make async module.exports = generateSiteMap()
module.exports = scanDirectory(settings.siteTitle, __dirname + settings.searchDir)
/** Generate full site map
*
* @returns {Object} full site map
*/
function generateSiteMap(){
return scanDirectory(settings.siteTitle, __dirname + settings.searchDir)
}
/** Generates a object containing a list of all pages
*
* @param {String} dir directory source of the pages
* @param {Array} files list of the file in the directory
* @returns {Object} siteMap list of pages
*/
function scanPages(dir, files){ function scanPages(dir, files){
var pages = {} var pages = {}
@@ -37,7 +50,12 @@ function scanPages(dir, files){
return pages return pages
} }
function scanDirectory(file, path){ /**
*
* @param {String} dirname directory name
* @param {String} path Path to the directory
*/
function scanDirectory(dirname, path){
var index var index
var files = fs.readdirSync(path); var files = fs.readdirSync(path);
@@ -56,11 +74,11 @@ function scanDirectory(file, path){
} }
return { return {
title: String (file), title: String (dirname),
type: "directory", type: "directory",
file: String (path), file: String (path),
index: (index) ? index : { index: (index) ? index : {
title: String (file), title: String (dirname),
type: 'index', type: 'index',
file: String (path) file: String (path)
}, },