Skip to content

Instantly share code, notes, and snippets.

@balupton
Last active July 27, 2016 10:40
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save balupton/4166806 to your computer and use it in GitHub Desktop.
Save balupton/4166806 to your computer and use it in GitHub Desktop.
DocPad: Automatically set custom Meta Data for items in a Collection
# Define our Configuration
docpadConfig =
# Define our own Collections
collections:
# Posts
# Anything outputted to the posts directory can be considered a post
# Sort the posts by newest first
# And set their layout to `post` automatically if it isn't already set
posts: (database) ->
database.findAllLive({relativeOutDirPath:'posts'},[date:-1]).on('add', (document) ->
document.setMetaDefaults(layout:'post')
)
# instead of database, you can also use @getCollection('documents') or whatever
# if the content you are filtering are just documents (will be faster if this is the case)
# Export our Configuration
module.exports = docpadConfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment