Create a gist now

Instantly share code, notes, and snippets.

@balupton /
Last active Dec 11, 2015

What would you like to do?
DocPad: Querying custom categories (via single categories object)
# ...
slug: 'a'
description: 'first letter of alphabet'
slug: 'b'
description: 'second letter of alphabet'
getDocumentsForCategory: (categoryId) ->
return @getCollection('documents').findAll(categories: $has: categoryId)
getCategoriesForDocument: (document) ->
document ?= @getDocument()
categoryIds = document.get('categories')
categories = @categories[categoryId] for categoryId in categoryIds
return categories
# ...
title: 'Happy new year!'
layout: post
categories: ['a','b']

Happy new year. Boom boom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment