docpad

How do I setup the Date URLs Plugin for DocPad?


I've recently converted from Octopress to Docpad and couldn't be happier. I like everything, but one thing bothers me. At the moment all paths on my site are built directly from the filename, e.g. www.site.com/posts/yyyy-mm-dd-title/. What I want to get is www.site.com/posts/yyyy/title. I found the Date URLs plugin, but cannot understand how to set it up. I tried inserting the relevant part into docpad.coffee as follows:

docpadConfig =

  plugins:
    dateurls:
      cleanurl: true
      trailingSlashes: true
      collectionName: 'posts'
      dateFormat: '/YYYY'

  templateData:
    site:

But nothing seems to change. The collection is defined as follows:

posts: ->
  @getCollection("html").findAllLive({relativeOutDirPath:'blog'},[date:-1]).on "add", (model) ->
    model.setMetaDefaults({layout:"post"})

--
EDIT (in response to Lukasz Gornicki)

A sample of metadata from the blog folder:

---
title: "Les Sapeurs"
date: 2014-09-25 07:39
comments: false
language: english
tags: video
keywords: anton zujev, antzoo, zujev, sapeurs, style, congo
description: Les Sapeurs are fashionistas from Congo, whose style is a political and social outcry.
---

A sample of metadata from the cast folder:

---
title: "Utan 7"
date: 2015-02-27 06:52
podfeed: utan
comments: true
---

I didn't try the debug mode before. Now I did, but I don't see anything special in the log. Here's the log file.


Solution

  • I've installed the plugin on my blog to check it out. I think there is a bug in documentation or it is just supper misleading. Documentation doesn't explicitly say that the url is build against the date metadata with dateFormat configuration and file basename without the date. I copied your configuration use it agains my blog with post 2015-02-16-test-test.html.md with metadata: date: 2014-09-25 9:49.

    result url: http://localhost:9778/2014/test-test/

    So the plugin works. Do you think that docpad doesn't pick up any configuration for the plugin? If you are configuring docpad with docpad.coffee I suggest you to validate the file, if it is created according to coffeescript rules and you have right indentation. Some time ago I had a situation that my config file grew a lot and some of the config was not picked up because of indentation.

    Or just give access to the project so I can see and tell you what is wrong.

    MORE DETAILS TO THE ANSWER AFTER CHECKING THE PROJECT: Filename can have a date. The plugin uses regex to take just the string out of the filename - basename.

    Locally I've commented out your hook into the renderBefore event, installed the plugin, added your config and all works as expected if it comes to the urls. So I get a URL like /2014/movie-quotes/ On the other hand it works when the server is started, but when I look on the out dir and try to generate the static content, it looks like the plugin doesn't work. Is this what you mean when saying that plugin doesn't work?