Skip to content

Commit 6fa7ada

Browse files
authored
Merge pull request #3830 from dailyrandomphoto/fix-create-new-post
fix(cli_new): omit 'p:', 's:', 'r:' properties in front-matter
2 parents 1b69a53 + 02fe561 commit 6fa7ada

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

lib/plugins/console/new.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ const reservedKeys = {
88
title: true,
99
layout: true,
1010
slug: true,
11+
s: true,
1112
path: true,
13+
p: true,
1214
replace: true,
15+
r: true,
1316
// Global options
1417
config: true,
1518
debug: true,

test/scripts/console/new.js

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ describe('new', () => {
8787
});
8888
});
8989

90+
it('slug - s', () => {
91+
const date = moment(now);
92+
const path = pathFn.join(hexo.source_dir, '_posts', 'foo.md');
93+
const body = [
94+
'title: Hello World',
95+
'date: ' + date.format('YYYY-MM-DD HH:mm:ss'),
96+
'tags:',
97+
'---'
98+
].join('\n') + '\n';
99+
100+
return n({
101+
_: ['Hello World'],
102+
s: 'foo'
103+
}).then(() => fs.readFile(path)).then(content => {
104+
content.should.eql(body);
105+
return fs.unlink(path);
106+
});
107+
});
108+
90109
it('path', () => {
91110
const date = moment(now);
92111
const path = pathFn.join(hexo.source_dir, '_posts', 'bar.md');
@@ -107,6 +126,26 @@ describe('new', () => {
107126
});
108127
});
109128

129+
it('path - p', () => {
130+
const date = moment(now);
131+
const path = pathFn.join(hexo.source_dir, '_posts', 'bar.md');
132+
const body = [
133+
'title: Hello World',
134+
'date: ' + date.format('YYYY-MM-DD HH:mm:ss'),
135+
'tags:',
136+
'---'
137+
].join('\n') + '\n';
138+
139+
return n({
140+
_: ['Hello World'],
141+
slug: 'foo',
142+
p: 'bar'
143+
}).then(() => fs.readFile(path)).then(content => {
144+
content.should.eql(body);
145+
return fs.unlink(path);
146+
});
147+
});
148+
110149
it('rename if target existed', () => {
111150
const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md');
112151

@@ -125,7 +164,14 @@ describe('new', () => {
125164
});
126165

127166
it('replace existing files', () => {
167+
const date = moment(now);
128168
const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md');
169+
const body = [
170+
'title: Hello World',
171+
'date: ' + date.format('YYYY-MM-DD HH:mm:ss'),
172+
'tags:',
173+
'---'
174+
].join('\n') + '\n';
129175

130176
return post.create({
131177
title: 'Hello World'
@@ -134,8 +180,31 @@ describe('new', () => {
134180
replace: true
135181
})).then(() => fs.exists(pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'))).then(exist => {
136182
exist.should.be.false;
137-
return fs.unlink(path);
138-
});
183+
}).then(() => fs.readFile(path)).then(content => {
184+
content.should.eql(body);
185+
}).finally(() => fs.unlink(path));
186+
});
187+
188+
it('replace existing files - r', () => {
189+
const date = moment(now);
190+
const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md');
191+
const body = [
192+
'title: Hello World',
193+
'date: ' + date.format('YYYY-MM-DD HH:mm:ss'),
194+
'tags:',
195+
'---'
196+
].join('\n') + '\n';
197+
198+
return post.create({
199+
title: 'Hello World'
200+
}).then(() => n({
201+
_: ['Hello World'],
202+
r: true
203+
})).then(() => fs.exists(pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'))).then(exist => {
204+
exist.should.be.false;
205+
}).then(() => fs.readFile(path)).then(content => {
206+
content.should.eql(body);
207+
}).finally(() => fs.unlink(path));
139208
});
140209

141210
it('extra data', () => {

0 commit comments

Comments
 (0)