Skip to content

Commit

Permalink
fix(main): preformat publish time before slug
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Jul 24, 2015
1 parent affb0f7 commit b8c7813
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -169,10 +169,10 @@ Formatter.prototype.preFormat = function (data) {
}
});

var slug = this._formatSlug(data);
data.properties.published = [data.properties.published && data.properties.published[0] ? new Date(data.properties.published[0]) : new Date()];

var slug = this._formatSlug(data);
data.properties.slug = slug ? [slug] : [];
data.properties.published = [data.properties.published && data.properties.published[0] ? new Date(data.properties.published[0]) : new Date()];

data.derived = {};

Expand Down
14 changes: 13 additions & 1 deletion test/formatter.spec.js
Expand Up @@ -238,7 +238,7 @@ describe('Formatter', function () {
formatter._formatSlug(baseMicroformatData).should.equal('foo-bar-abc');
});

it('should ulimately fall back to publish time', function () {
it('should ultimately fall back to publish time', function () {
delete baseMicroformatData.properties.name;
formatter._formatSlug(baseMicroformatData).should.equal('52441');
});
Expand Down Expand Up @@ -393,6 +393,18 @@ describe('Formatter', function () {
.that.deep.equals(['hello world']);
});

it('should be able to base slug on default publish times', function () {
delete baseMicroformatData.properties.name;
delete baseMicroformatData.properties.published;
delete baseMicroformatData.properties.slug;

return formatter.preFormat(baseMicroformatData)
.should.eventually
.have.deep.property('properties.slug')
.that.deep.equals(['51600']);
});


});

describe('_formatFilesSlug', function () {
Expand Down

0 comments on commit b8c7813

Please sign in to comment.