From 2cc2606967f2947f3fcd49fe2c886ce91061ddd8 Mon Sep 17 00:00:00 2001 From: Mats van Reenen Date: Mon, 27 Jul 2020 20:09:20 +0200 Subject: [PATCH] add notes --- siteMap.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/siteMap.js b/siteMap.js index d2094d6..8b80334 100755 --- a/siteMap.js +++ b/siteMap.js @@ -1,12 +1,25 @@ const settings = require('./settings') const fs = require('fs') -//TODO: make async -module.exports = scanDirectory(settings.siteTitle, __dirname + settings.searchDir) +module.exports = generateSiteMap() +/** 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){ var pages = {} - + for(i=files.length-1; i >= 0; i--){ var file, path, urlName, extention, fileName file = files[i] // full file name @@ -37,7 +50,12 @@ function scanPages(dir, files){ 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 files = fs.readdirSync(path); @@ -56,11 +74,11 @@ function scanDirectory(file, path){ } return { - title: String (file), + title: String (dirname), type: "directory", file: String (path), index: (index) ? index : { - title: String (file), + title: String (dirname), type: 'index', file: String (path) },