Skip to content

Instantly share code, notes, and snippets.

@greduan
Forked from balupton/README.md
Last active December 19, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greduan/5977871 to your computer and use it in GitHub Desktop.
Save greduan/5977871 to your computer and use it in GitHub Desktop.

DocPad: Clean dates in post URLs

Creates URLs like /2012/12/15/merry-xmas.html for your blog posts.

Requires momentjs to be installed: npm install --save moment

# Import
moment = require('moment')
# Configuration
docpadConfig =
# =================================
# Collections
collections:
posts: ->
@getCollection('html').findAllLive({relativeOutDirPath:'archives'},[{date:-1}]).on 'add', (model) ->
dateUrl = '/archives' + moment(model.get('date')).format('/YYYY/MM/DD') + '/' + model.get('basename')
model.addUrl(dateUrl).setMetaDefaults({url: dateUrl})
model.setMetaDefaults({layout: 'post'})
# Export
module.exports = docpadConfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment