Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed async error when making each post directory #4

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 33 additions & 9 deletions quill/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,38 @@ var createSiteDirectory = function(directory, callback) {
});
};

/**
* createPostDirectory
*
* Creates the directory where each post's index.html will exist. Removes any
* existing directory beforehand.
*
* @param String directory Directory where the static site will be stored
* @param HTML output for post
* @param Function callback Callback function
*/
var createPostDirectory = function(directory, layoutHTML, callback) {
var outputFilename;

path.exists(directory, function(exists) {
if(exists) {
wrench.rmdirSyncRecursive(directory);
}

fs.mkdir(directory, function() {
outputFilename = path.join(directory, 'index.html');

fs.writeFile(outputFilename, layoutHTML, function(err) {
if(err) {
return callback(err);
}
callback();
});

});
});
};

/**
* findPosts
*
Expand Down Expand Up @@ -226,15 +258,7 @@ var generateHTMLFiles = function(files, layout, outputDir, config, callback) {

var outputFileDir = path.join(outputDir, file.url);

fs.mkdir(outputFileDir, function() {
outputFilename = path.join(outputFileDir, 'index.html');
var fileRes = fs.writeFile(outputFilename, layoutHTML, function(err) {
if(err) {
return callback(err);
}
compileCompleted();
});
});
createPostDirectory(outputFileDir, layoutHTML, compileCompleted);
}

var sortByTimestamp = function(a, b) {
Expand Down