Browse Source

Fix guide generator

beginners-guide
Node 7 years ago
parent
commit
88ba5ca5da
No known key found for this signature in database GPG Key ID: 8E1B4DC29040BD90
  1. 10
      guide-generator.js
  2. 18
      utils/generatePages.js

10
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...');

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

Loading…
Cancel
Save