diff --git a/bin/cli.js b/bin/cli.js index 9177cc0..fec466d 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -6,7 +6,8 @@ var GhostExport = require('..'), .version(package.version) .usage('[options...] [source] [destination]') .option('-d --drafts', 'Export drafts only') - .option('-a --all', 'Export both published posts and drafts'); + .option('-a --all', 'Export both published posts and drafts') + .option('-t --title', 'Export including title at the beginning of the file'); program.on('--help', function(){ console.log(' Description:'); @@ -32,7 +33,8 @@ var args = { source: program.args.shift(), destination: program.args.shift(), published: (!program.drafts || program.all) ? true : false, - drafts: (program.drafts || program.all) + drafts: (program.drafts || program.all), + title: program.title ? true : false }; GhostExport(args, function(err, count) { diff --git a/lib/ghost-export.js b/lib/ghost-export.js index 49e5359..1726be3 100644 --- a/lib/ghost-export.js +++ b/lib/ghost-export.js @@ -1,5 +1,6 @@ var dateFormat = require('dateformat'), fs = require('fs'), + os = require('os'), path = require('path'), sqlite3 = require('sqlite3'); @@ -37,7 +38,15 @@ module.exports = function(args, callback) { var outFile = path.join(args.destination, name); try { - fs.writeFileSync(outFile, row.markdown); + var toWrite = []; + // Post title + if (args.title) { + toWrite.push('# ' + row.title); + toWrite.push(''); + } + // Post content + toWrite.push(row.markdown); + fs.writeFileSync(outFile, toWrite.join(os.EOL)); } catch(err) { callback(err, 0); }