Skip to content

Commit

Permalink
relative_url helper: replace trailing slash with index.html.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed May 18, 2015
1 parent 021456c commit 03077e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/plugins/helper/relative_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ function relativeUrlHelper(from, to){
out.unshift('..');
}

var outLength = out.length;

// If the last 2 elements of `out` is empty strings, replace them with `index.html`.
if (outLength > 1 && !out[outLength - 1] && !out[outLength] - 2){
out = out.slice(0, outLength - 2).concat('index.html');
}

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

Expand Down
8 changes: 4 additions & 4 deletions test/scripts/helpers/relative_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe('relative_url', function(){
});

it('to root', function(){
relativeURL('index.html', '/').should.eql('/');
relativeURL('foo/', '/').should.eql('../');
relativeURL('foo/index.html', '/').should.eql('../');
relativeURL('index.html', '/').should.eql('index.html');
relativeURL('foo/', '/').should.eql('../index.html');
relativeURL('foo/index.html', '/').should.eql('../index.html');
});
});
});

0 comments on commit 03077e7

Please sign in to comment.