Skip to content

Commit

Permalink
fix(main): by default don't base slug on content
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Jul 24, 2015
1 parent f0cc044 commit affb0f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -34,6 +34,7 @@ var Formatter = function (options) {

this.relativeTo = options.relativeTo;
this.markdown = !options.noMarkdown;
this.contentSlug = !!options.contentSlug;
this.defaults = options.defaults;
};

Expand Down Expand Up @@ -100,7 +101,7 @@ Formatter.prototype._formatSlug = function (data) {
if (data.properties.name) {
name = data.properties.name[0].trim();
}
if (!name && data.properties.content) {
if (!name && data.properties.content && this.contentSlug) {
name = data.properties.content[0].trim();
name = ent.decode(name.replace(htmlRegexp, ''));
}
Expand Down
5 changes: 4 additions & 1 deletion test/formatter.spec.js
Expand Up @@ -225,20 +225,21 @@ describe('Formatter', function () {

it('should fall back to base slug on content', function () {
delete baseMicroformatData.properties.name;
formatter = new Formatter({ contentSlug: true });
formatter._formatSlug(baseMicroformatData).should.equal('hello-world');
});

it('should ignore html-tags when basing slug on content', function () {
delete baseMicroformatData.properties.name;
baseMicroformatData.properties.content = ['<h1>Foo</h1> Bar &amp; <strong>Abc</strong>'];
formatter = new Formatter({ contentSlug: true });
// Test twice so that we don't get a non-reusable regexp!
formatter._formatSlug(baseMicroformatData).should.equal('foo-bar-abc');
formatter._formatSlug(baseMicroformatData).should.equal('foo-bar-abc');
});

it('should ulimately fall back to publish time', function () {
delete baseMicroformatData.properties.name;
delete baseMicroformatData.properties.content;
formatter._formatSlug(baseMicroformatData).should.equal('52441');
});

Expand All @@ -248,6 +249,7 @@ describe('Formatter', function () {

baseMicroformatData.properties.content = baseMicroformatData.properties.name;
delete baseMicroformatData.properties.name;
formatter = new Formatter({ contentSlug: true });
formatter._formatSlug(baseMicroformatData).should.equal('one-two-three-four-five');
});

Expand All @@ -264,6 +266,7 @@ describe('Formatter', function () {
it('should ensure slug doesnt start or end with a dash', function () {
delete baseMicroformatData.properties.name;
baseMicroformatData.properties.content = [',One Two Three Four Five, Six Seven'];
formatter = new Formatter({ contentSlug: true });
formatter._formatSlug(baseMicroformatData).should.equal('one-two-three-four-five');
});

Expand Down

0 comments on commit affb0f7

Please sign in to comment.