Skip to content

Commit

Permalink
also check resolved url for is-active checks
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickarlt committed Feb 24, 2019
1 parent db8b3da commit cb5dedc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/helpers/link-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ module.exports = function(acetate) {
} else if (options.requireExactMatch) {
isActive = currentUrl === resolvedUrl;
} else {
let parsedUrl = url.parse(finalUrl);
isActive = currentUrl.match(parsedUrl.pathname) && finalUrl !== "/";
let parsedFinalUrl = url.parse(finalUrl);
let parsedResolvedUrl = url.parse(resolvedUrl);
isActive =
(currentUrl.match(parsedResolvedUrl.pathname) ||
currentUrl.match(parsedFinalUrl.pathname)) &&
finalUrl !== "/";
}

const classes = isActive
Expand Down
2 changes: 2 additions & 0 deletions test/Acetate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ test("should create anchors code with a built in helper", t => {
{% link '/nested/', 'Page', currentUrl='/' %}
{% link '/nested/', 'Page', currentUrl='/nested/' %}
{% link relativePath + '/nested/page/', 'Link With relativePath' %}
{% link '../../../latest/guide/', 'Guide', currentUrl='/latest/guide/create-a-starter-app/' %}
`;

const page = createPage("nested/page/index.html", template);
Expand All @@ -337,6 +338,7 @@ test("should create anchors code with a built in helper", t => {
<a href="/nested/">Page</a>
<a href="/nested/" class="is-active">Page</a>
<a href="../../nested/page/" class="is-active">Link With relativePath</a>
<a href="../../../latest/guide/" class="is-active">Guide</a>
`;

return acetate.renderPage(page).then(output => {
Expand Down

0 comments on commit cb5dedc

Please sign in to comment.