Skip to content

Commit

Permalink
cleaner implementation of default author
Browse files Browse the repository at this point in the history
  • Loading branch information
sontek committed Feb 17, 2012
1 parent 273ea6f commit b960978
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/commands/post.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
var smith = require("../blacksmith"),
fs2 = require('../fs2'),
winston = require('winston'),
path = require('path'),
path = require('path'),
prompt = require("prompt");

module.exports = function() {
winston.info("Executing command "+"post".yellow);

if(smith.config.global.store.defaultAuthor && path.existsSync('./authors/'+smith.config.global.store.defaultAuthor+'.json')) {
var authors = require("../loaders/authors").load(true);
var defaultAuthor = authors[smith.config.global.store.defaultAuthor].file.store.name;
var defaultAuthor = smith.config.get("defaultAuthor"),
defaultAuthorName;
if(defaultAuthor && path.existsSync('./authors/'+defaultAuthor+'.json')) {
var author = require("../loaders/authors").load(true)[defaultAuthor];
if(author) {
defaultAuthorName = author.get("name");
}
}

prompt.start();
Expand All @@ -20,22 +24,20 @@ module.exports = function() {
},
{
name: "author",
message: "Specify the author" + (defaultAuthor ? " (empty to use '"+defaultAuthor+"')" : "")
message: "Specify the author" + (defaultAuthorName ? " (empty to use '"+defaultAuthorName+"')" : "")
}
], function (err, res) {
if (err) {
winston.error(err.stack);
cb(1);
}

if(res.author === "")
res.author = smith.config.global.store.defaultAuthor;
if(res.author === "") {
res.author = defaultAuthorName;
}

var folder = res.title.toLowerCase().replace(/\W+/g, '-');

if(smith.config.global.store.contentDir)
folder = smith.config.global.store.contentDir + "/" + folder;

//TODO: Check authors

winston.warn('blacksmith'.yellow+' is about to write '
Expand Down

0 comments on commit b960978

Please sign in to comment.