1 | 'use strict';
|
2 |
|
3 | const tildify = require('tildify');
|
4 | const chalk = require('chalk');
|
5 |
|
6 | const reservedKeys = {
|
7 | _: true,
|
8 | title: true,
|
9 | layout: true,
|
10 | slug: true,
|
11 | path: true,
|
12 | replace: true,
|
13 |
|
14 | config: true,
|
15 | debug: true,
|
16 | safe: true,
|
17 | silent: true
|
18 | };
|
19 |
|
20 | function newConsole(args) {
|
21 |
|
22 | if (!args._.length) {
|
23 | return this.call('help', {_: ['new']});
|
24 | }
|
25 |
|
26 | const data = {
|
27 | title: args._.pop(),
|
28 | layout: args._.length ? args._[0] : this.config.default_layout,
|
29 | slug: args.s || args.slug,
|
30 | path: args.p || args.path
|
31 | };
|
32 |
|
33 | const keys = Object.keys(args);
|
34 | let key = '';
|
35 | const self = this;
|
36 |
|
37 | for (let i = 0, len = keys.length; i < len; i++) {
|
38 | key = keys[i];
|
39 | if (!reservedKeys[key]) data[key] = args[key];
|
40 | }
|
41 |
|
42 | return this.post.create(data, args.r || args.replace).then(post => {
|
43 | self.log.info('Created: %s', chalk.magenta(tildify(post.path)));
|
44 | });
|
45 | }
|
46 |
|
47 | module.exports = newConsole;
|