Last active
August 29, 2015 14:22
-
-
Save chrtze/4862d962c093f291ec32 to your computer and use it in GitHub Desktop.
Ghost: Display All Tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//insert at line 61 in: /core/server/controllers/frontend.js | |
function formatPageResponse(posts, page) { | |
// Delete email from author for frontend output | |
// TODO: do this on API level if no context is available | |
posts = _.each(posts, function (post) { | |
if (post.author) { | |
delete post.author.email; | |
} | |
return post; | |
}); | |
return { | |
posts: posts, | |
pagination: page.meta.pagination, | |
all_tags: formatTags(posts) | |
}; | |
} | |
function formatTags(posts) { | |
var check = []; | |
var tags = []; | |
posts.forEach(function(p,i) { | |
p.tags.forEach(function(t,j) { | |
if(check.indexOf(t.name) < 0) { | |
tags.push(t); | |
check.push(t.name); | |
} | |
}); | |
}); | |
return tags; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{#foreach all_tags}} | |
<li><a href="{{url}}">{{name}}</a></li> | |
{{/foreach}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment