diff --git a/guide-generator.js b/guide-generator.js index 433d9fc..614bfb8 100644 --- a/guide-generator.js +++ b/guide-generator.js @@ -40,7 +40,15 @@ if ( args.indexOf('--help') > -1 || args.length === 0 ) { return; } -generatePages(markdownDir, all, __dirname) +const options = { + all: all, + file: file, + author: author +}; + +//generateArchive(__dirname, markdownDir, options) +//generatePages(markdownDir, all, __dirname, file) +generatePages(__dirname, markdownDir, options) .then((files) => { console.log('Finished generating files: ', files); console.log('Writing guides archive...'); diff --git a/utils/generatePages.js b/utils/generatePages.js index 7f9ceb8..7e7469e 100644 --- a/utils/generatePages.js +++ b/utils/generatePages.js @@ -4,13 +4,12 @@ const path = require('path'); const createHTML = require('./createHTML.js'); -const generatePages = async (markdownDir, all, rootDir) => { - +const generatePages = async (rootDir, markdownDir, options) => { const guidesDir = path.resolve(rootDir, 'guides'); let markdownFile; let htmlFile; - if (all) { + if (options.all) { // get all markdown files and createHTML for each // returning a promise so we can have better control over async logic flow // since the `fs.readdir` is an async callback that we'd like to `await` on @@ -28,7 +27,9 @@ const generatePages = async (markdownDir, all, rootDir) => { } else if (fs.statSync(path.resolve(markdownDir, file)).isDirectory()) { // if we find a folder inside the directory // we need to do a recursive call to convert (all) the guides in that directory - await generatePages(path.resolve(markdownDir,file), true, rootDir); + await generatePages(rootDir, path.resolve(markdownDir,file), { + all: true + }); } } // once we've converted all markdown files in the folder @@ -37,9 +38,12 @@ const generatePages = async (markdownDir, all, rootDir) => { }); }) } else { - markdownFile = path.resolve(markdownDir, file); - htmlFile = path.resolve(guidesDir, file.replace(/\.[^/.]+$/, ".html")); - await createHTML(markdownFile, htmlFile, author, postMeta); + markdownFile = path.resolve(markdownDir, options.file); + htmlFile = path.resolve(guidesDir, options.file.replace(/\.[^/.]+$/, ".html")); + postMeta = ''; + + await createHTML(markdownFile, htmlFile, options.author, '', rootDir); + return options.file; } }