'use strict';

var url = require('url');
var _ = require('lodash');
var relative_url = require('./relative_url');

function urlForHelper(path, options) {
  path = path || '/';

  if (path[0] === '#' || path.substring(0, 2) === '//') {
    return path;
  }

  var config = this.config;
  var root = config.root;
  var data = url.parse(path);

  options = _.assign({
    relative: config.relative_link
  }, options);

  // Exit if this is an external path
  if (data.protocol) {
    return path;
  }

  // Resolve relative url
  if (options.relative) {
    return relative_url(this.path, path);
  }

  // Prepend root path
  path = root + path;

  return path.replace(/\/{2,}/g, '/');
}

module.exports = urlForHelper;

@@ -64,54 +64,8 @@
 h');
-%0Avar relative_url = require('./relative_url');
 %0A%0Afu
@@ -509,16 +509,21 @@
  return 
+this.
 relative

Revert "fix relative_url reference (#2656)" (#2667)