Skip to content

Commit

Permalink
Merge pull request #54 from suprMax/master
Browse files Browse the repository at this point in the history
fixing drafts showing up when searching for posts by tags/categories, also fixes #33
  • Loading branch information
jsantell committed Sep 19, 2013
2 parents 56eabc2 + 3c18aa6 commit c0b13b2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/poet/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,23 @@ function createHelpers (poet) {
return Math.ceil(getPosts(poet).length / options.postsPerPage);
},
postsWithTag: function (tag) {
if (!options.showDrafts) {
return getPosts(poet).filter(function (post) {
return post.tags && ~post.tags.indexOf(tag) && !post.draft;
});
}

return getPosts(poet).filter(function (post) {
return post.tags && ~post.tags.indexOf(tag);
});
},
postsWithCategory: function (category) {
if (!options.showDrafts) {
return getPosts(poet).filter(function (post) {
return post.category === category && !post.draft;
});
}

return getPosts(poet).filter(function (post) {
return post.category === category;
});
Expand Down
22 changes: 22 additions & 0 deletions test/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ describe('helpers.postsWithTag()', function () {
});
});

describe('helpers.postsWithTag()', function () {
it('should not see drafts on production', function (done) {
setup(function (poet) {
poet.options.showDrafts = false;
var posts = poet.helpers.postsWithTag('d');
(posts.length).should.equal(1);
done();
}, done);
});
});

describe('helpers.postsWithCategories()', function () {
it('should return posts ordered by date, newest first', function (done) {
setup(function (poet) {
Expand All @@ -121,6 +132,17 @@ describe('helpers.postsWithCategories()', function () {
});
});

describe('helpers.postsWithCategories()', function () {
it('should not see drafts on production', function (done) {
setup(function (poet) {
poet.options.showDrafts = false;
var posts = poet.helpers.postsWithCategory('other cat');
(posts.length).should.equal(1);
done();
}, done);
});
});

function setup (callback, done) {
var app = express();
var poet = Poet(app, {
Expand Down

0 comments on commit c0b13b2

Please sign in to comment.