Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:');
Expand All @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion lib/ghost-export.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var dateFormat = require('dateformat'),
fs = require('fs'),
os = require('os'),
path = require('path'),
sqlite3 = require('sqlite3');

Expand Down Expand Up @@ -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);
}
Expand Down