From 679fc4a9fa55d5791805d2b89e4d0ec37d2f30f6 Mon Sep 17 00:00:00 2001 From: cgeek Date: Sun, 16 Aug 2015 18:01:53 +0200 Subject: [PATCH 1/3] Added --title option to include post title as first line in the markdown --- bin/cli.js | 6 ++++-- lib/ghost-export.js | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) 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..ee4a181 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,14 @@ 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); + } + // Post content + toWrite.push(row.markdown); + fs.writeFileSync(outFile, toWrite.join(os.EOL)); } catch(err) { callback(err, 0); } From 5a016e05ff00ed2d8440ab41f5b432d948b811b3 Mon Sep 17 00:00:00 2001 From: cgeek Date: Sun, 16 Aug 2015 18:16:39 +0200 Subject: [PATCH 2/3] Missing space for title --- lib/ghost-export.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ghost-export.js b/lib/ghost-export.js index ee4a181..e412398 100644 --- a/lib/ghost-export.js +++ b/lib/ghost-export.js @@ -41,7 +41,7 @@ module.exports = function(args, callback) { var toWrite = []; // Post title if (args.title) { - toWrite.push('#' + row.title); + toWrite.push('# ' + row.title); } // Post content toWrite.push(row.markdown); From fa8033f97afa97c96644fdb71cc73f0c318b3787 Mon Sep 17 00:00:00 2001 From: cgeek Date: Sun, 16 Aug 2015 19:16:39 +0200 Subject: [PATCH 3/3] Add a newline after title --- lib/ghost-export.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ghost-export.js b/lib/ghost-export.js index e412398..1726be3 100644 --- a/lib/ghost-export.js +++ b/lib/ghost-export.js @@ -42,6 +42,7 @@ module.exports = function(args, callback) { // Post title if (args.title) { toWrite.push('# ' + row.title); + toWrite.push(''); } // Post content toWrite.push(row.markdown);