Skip to content

Commit

Permalink
Merge pull request #3830 from dailyrandomphoto/fix-create-new-post
Browse files Browse the repository at this point in the history
fix(cli_new): omit 'p:', 's:', 'r:' properties in front-matter
  • Loading branch information
curbengh authored Nov 9, 2019
2 parents 1b69a53 + 02fe561 commit 6fa7ada
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/plugins/console/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ const reservedKeys = {
title: true,
layout: true,
slug: true,
s: true,
path: true,
p: true,
replace: true,
r: true,
// Global options
config: true,
debug: true,
Expand Down
73 changes: 71 additions & 2 deletions test/scripts/console/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ describe('new', () => {
});
});

it('slug - s', () => {
const date = moment(now);
const path = pathFn.join(hexo.source_dir, '_posts', 'foo.md');
const body = [
'title: Hello World',
'date: ' + date.format('YYYY-MM-DD HH:mm:ss'),
'tags:',
'---'
].join('\n') + '\n';

return n({
_: ['Hello World'],
s: 'foo'
}).then(() => fs.readFile(path)).then(content => {
content.should.eql(body);
return fs.unlink(path);
});
});

it('path', () => {
const date = moment(now);
const path = pathFn.join(hexo.source_dir, '_posts', 'bar.md');
Expand All @@ -107,6 +126,26 @@ describe('new', () => {
});
});

it('path - p', () => {
const date = moment(now);
const path = pathFn.join(hexo.source_dir, '_posts', 'bar.md');
const body = [
'title: Hello World',
'date: ' + date.format('YYYY-MM-DD HH:mm:ss'),
'tags:',
'---'
].join('\n') + '\n';

return n({
_: ['Hello World'],
slug: 'foo',
p: 'bar'
}).then(() => fs.readFile(path)).then(content => {
content.should.eql(body);
return fs.unlink(path);
});
});

it('rename if target existed', () => {
const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md');

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

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

return post.create({
title: 'Hello World'
Expand All @@ -134,8 +180,31 @@ describe('new', () => {
replace: true
})).then(() => fs.exists(pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'))).then(exist => {
exist.should.be.false;
return fs.unlink(path);
});
}).then(() => fs.readFile(path)).then(content => {
content.should.eql(body);
}).finally(() => fs.unlink(path));
});

it('replace existing files - r', () => {
const date = moment(now);
const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md');
const body = [
'title: Hello World',
'date: ' + date.format('YYYY-MM-DD HH:mm:ss'),
'tags:',
'---'
].join('\n') + '\n';

return post.create({
title: 'Hello World'
}).then(() => n({
_: ['Hello World'],
r: true
})).then(() => fs.exists(pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'))).then(exist => {
exist.should.be.false;
}).then(() => fs.readFile(path)).then(content => {
content.should.eql(body);
}).finally(() => fs.unlink(path));
});

it('extra data', () => {
Expand Down

0 comments on commit 6fa7ada

Please sign in to comment.