|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|