Skip to content

Commit

Permalink
Merge pull request hexojs#1406 from liuhongjiang/add_root_to_urlForHe…
Browse files Browse the repository at this point in the history
…lper

Prepend root path to urlForHelper
  • Loading branch information
tommy351 committed Aug 2, 2015
2 parents b1faffd + 5257363 commit 14d2b9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/plugins/helper/url_for.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ function urlForHelper(path, options){
}

// Prepend root path
if(path === '/') {
return root;
} else if (path[0] !== '/'){
return root + path;
}
path = root + path;

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

module.exports = urlForHelper;
2 changes: 2 additions & 0 deletions test/scripts/helpers/url_for.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ describe('url_for', function(){
ctx.config.root = '/';
urlFor('index.html').should.eql('/index.html');
urlFor('/').should.eql('/');
urlFor('/index.html').should.eql('/index.html');

ctx.config.root = '/blog/';
urlFor('index.html').should.eql('/blog/index.html');
urlFor('/').should.eql('/blog/');
urlFor('/index.html').should.eql('/blog/index.html');
});

it('internal url (relative on)', function(){
Expand Down

0 comments on commit 14d2b9b

Please sign in to comment.