Grunt Assemble Canonical Urls

Here's a simple handlebars helper to get canonical urls onto your pages.

HTML:

<link rel="canonical" href="{{canonical dirname basename ext}}">

helper.js

/**
   * http://blog.grahamlicence.co.uk/[object Object]/undefinedundefined
   * Builds a canonical url, stripping out dist dir and index.html
   * @param  {String} dirname file firectory location
   * @param  {String} basename filename
   * @param  {String} ext file extension
   * @return {String} formattedUrl Canonical url
   */
Handlebars.registerHelper('canonical', function(dirname, basename, ext) {
    var base = 'http://blog.grahamlicence.co.uk/',
        url = dirname + '/' + basename + ext,
        path = url.replace('dist/', '').replace('index.html', ''),
        formattedUrl = base + path;

    return formattedUrl;
});