Skip to content

Commit

Permalink
Prepend root path to urlForHelper
Browse files Browse the repository at this point in the history
When user configures a prefix path as root path, urlForHelper can not
resolve url like '/archives' correctly with the prefix root path.

Resolves: hexojs#1105
  • Loading branch information
liuhongjiang committed Jul 21, 2015
1 parent b1faffd commit 5257363
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 5257363

Please sign in to comment.