Skip to content

Commit

Permalink
Merge differences of slug creation and overrides per post
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell committed Feb 2, 2014
1 parent 0bbae82 commit 73712ba
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/poet/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ exports.getTemplate = getTemplate;
function convertStringToSlug(str){
return str
.toLowerCase()
.replace(/[^\w ]+/g,'')
.replace(/[^\w- ]+/g,'')
.replace(/ +/g,'-');
}

Expand All @@ -185,7 +185,7 @@ function createPost (filePath, options) {
post.date = new Date(post.date);
post.content = body;
// url slug for post
post.slug = convertStringToSlug(post.title);
post.slug = convertStringToSlug(post.slug || post.title);
post.url = createURL(getRoute(options.routes, 'post'), post.slug);
post.preview = getPreview(post, body, options);
return post;
Expand Down
3 changes: 1 addition & 2 deletions test/_postsJson/test1.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"tags" : [ "a", "b" ],
"category" : "testing",
"date" : "7-10-2012",
"arbitrary" : "arbitrary content",
"slug": "test-one"
"arbitrary" : "arbitrary content"
}}}

*Lorem ipsum* dolor sit amet, consectetur adipisicing elit.
Expand Down
1 change: 0 additions & 1 deletion test/_postsYaml/test1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ tags:
category: testing
date: 7-10-2012
arbitrary: arbitrary content
slug: test-one
---

*Lorem ipsum* dolor sit amet, consectetur adipisicing elit.
Expand Down
19 changes: 18 additions & 1 deletion test/posts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('Posts', function () {
var
app = express(),
poet = Poet(app, {
posts: './test/test.posts'
posts: './test/test-posts/period.path'
});

poet.init().then(function () {
Expand All @@ -158,4 +158,21 @@ describe('Posts', function () {
}).then(null, done);
});
});

describe('Post Attributes', function () {
it('slug attribute overrides default slug and changes URL', function (done) {
var
app = express(),
poet = Poet(app, {
posts: './test/test-posts/slug'
});

poet.init().then(function () {
var posts = poet.helpers.getPosts();
posts[0].slug.should.be.equal('custom-slug');
posts[0].url.should.be.equal('/post/custom-slug');
done();
}).then(null, done);
});
});
});
File renamed without changes.
12 changes: 12 additions & 0 deletions test/test-posts/slug/test1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{{
"title" : "Test Post One",
"tags" : [ "a", "b" ],
"category" : "testing",
"date" : "7-10-2012",
"arbitrary" : "arbitrary content",
"slug": "custom-slug"
}}}

*Lorem ipsum* dolor sit amet, consectetur adipisicing elit.

# Header 1 #

0 comments on commit 73712ba

Please sign in to comment.