Skip to content

Commit

Permalink
Ensure url parameters are consistent (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
bameyrick authored Mar 7, 2019
1 parent 018edf7 commit 4024ffe
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions lib/helpers/navigation-helper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { orderBy } from 'lodash';

export function navigationHelper({ pages, ignorePaths }) {
if (ignorePaths) {
pages = pages.filter(page => !ignorePaths.includes(page.path));
export function navigationHelper({ pages, ignoreURLs }) {
if (ignoreURLs) {
pages = pages.filter(page => !ignoreURLs.includes(page.url));
}

pages = orderBy(pages, 'sortOrder');
Expand Down
6 changes: 3 additions & 3 deletions lib/helpers/sub-navigation-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export function subNavigationHelper({ pageInfo, anchorLinks }) {
const groups = [];

if (anchorLinks) {
const path = `${sourcePath}${pageInfo.path}/index.njk`;
const path = `${sourcePath}${pageInfo.url}/index.njk`;

if (fs.existsSync(path)) {
const item = items.find(item => item.path === pageInfo.path);
const item = items.find(item => item.url === pageInfo.url);
const raw = fs.readFileSync(path, 'utf8');

const matches = raw
Expand All @@ -29,7 +29,7 @@ export function subNavigationHelper({ pageInfo, anchorLinks }) {

const anchors = matches.map(match => ({
title: match,
path: `#${match
url: `#${match
.trim()
.toLowerCase()
.replace(/\s/g, '-')}`
Expand Down
12 changes: 6 additions & 6 deletions lib/nunjucks-html-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ function buildSiteMap(context) {
title,
sortOrder,
group,
path: path.replace('/index.njk', '').replace('.njk', '') || '/'
url: path.replace('/index.njk', '').replace('.njk', '') || '/'
});
} else {
const newRef = ref.find(page => page.path === `/${part}`);
const newRef = ref.find(page => page.url === `/${part}`);

if (newRef) {
if (!newRef.children) {
Expand Down Expand Up @@ -118,7 +118,7 @@ function getPageInfo(context) {
}

if (Array.isArray(pageRef)) {
pageRef = pageRef.find(page => page.path === pathRef);
pageRef = pageRef.find(page => page.url === pathRef);
}
}
});
Expand All @@ -129,9 +129,9 @@ function getPageInfo(context) {

path = path.replace('/index.njk', '').replace('.njk', '') || '/';

return { path, siteMap, children, parent, title };
return { url: path, siteMap, children, parent, title };
} else {
return { path };
return { url: path };
}
}

Expand Down Expand Up @@ -166,7 +166,7 @@ export default async function(source) {
const options = loaderUtils.getOptions(this) || {};
const pageInfo = getPageInfo(this);
const frontmatterData = frontmatter(source).data;
const isExample = pageInfo.path.includes('/examples/');
const isExample = pageInfo.url.includes('/examples/');

// Remove frontmatter from source
source = removeFrontmatterFromString(source);
Expand Down
6 changes: 3 additions & 3 deletions src/components/header/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<ul class="header-service-nav__list" aria-label="{{ params.serviceLinks.ariaListLabel }}" role="menubar">
{% for item in params.serviceLinks.items %}
<li class="header-service-nav__item">
<a href="{{ item.path }}" class="header-service-nav__link" role="menuitem">{{ item.title }}</a>
<a href="{{ item.url }}" class="header-service-nav__link" role="menuitem">{{ item.title }}</a>
</li>
{% endfor %}
</ul>
Expand Down Expand Up @@ -82,8 +82,8 @@
<nav class="header-nav header-nav--mobile js-header-nav" id="{{ params.navigation.id }}" aria-label="{{ params.navigation.ariaLabel }}">
<ul class="header-nav__list" aria-label="{{ params.navigation.ariaListLabel }}" role="menubar">
{% for item in params.navigation.items %}
<li class="header-nav__item {{ item.classes }}{{ ' header-nav__item--active' if (item.path == params.navigation.currentPath) or (item.path in params.navigation.currentPath) }}">
<a href="{{ item.path }}" class="header-nav__link" role="menuitem">{{ item.title }}</a>
<li class="header-nav__item {{ item.classes }}{{ ' header-nav__item--active' if (item.url == params.navigation.currentPath) or (item.url in params.navigation.currentPath) }}">
<a href="{{ item.url }}" class="header-nav__link" role="menuitem">{{ item.title }}</a>
</li>
{% endfor %}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions src/components/section-navigation/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<nav class="section-nav" id="{{ params.id }}" aria-label="{{ params.ariaLabel }}">
<ul class="section-nav__list" aria-label="{{ params.ariaListLabel }}" role="menubar">
{% for item in params.items %}
<li class="section-nav__item {{ item.classes }}{{ ' section-nav__item--active' if (item.path == params.currentPath) or (item.path in params.currentPath) }}">
<a href="{{ item.path }}" class="section-nav__link" role="menuitem">{{ item.title }}</a>
<li class="section-nav__item {{ item.classes }}{{ ' section-nav__item--active' if (item.url == params.currentPath) or (item.url in params.currentPath) }}">
<a href="{{ item.url }}" class="section-nav__link" role="menuitem">{{ item.title }}</a>
</li>
{% endfor %}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions src/views/layouts/_home.njk
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"classes": "nav--inline nav--light nav--header nav--h-m js-main-nav",
"ariaLabel": "Main menu",
"ariraListLabel": "Navigation menu",
"currentPath": pageInfo.path,
"currentPath": pageInfo.url,
"items": helpers.navigationHelper({
"pages": pageInfo.siteMap,
"ignorePaths": ["/"]
"ignoreURLs": ["/"]
})
}
})
Expand Down
6 changes: 3 additions & 3 deletions src/views/layouts/_page.njk
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"classes": "nav--inline nav--light nav--header nav--h-m js-main-nav",
"ariaLabel": "Main menu",
"ariraListLabel": "Navigation menu",
"currentPath": pageInfo.path,
"currentPath": pageInfo.url,
"items": helpers.navigationHelper({
"pages": pageInfo.siteMap,
"ignorePaths": ["/"]
"ignoreURLs": ["/"]
})
}
})
Expand All @@ -45,7 +45,7 @@
patternlibSubNavigation({
"ariaLabel": "Sub menu",
"ariraListLabel": "Child menu",
"currentPath": pageInfo.path,
"currentPath": pageInfo.url,
"items": group.items
})
}}
Expand Down
6 changes: 3 additions & 3 deletions src/views/partials/sub-navigation/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<nav class="patternlib-subnav" aria-label="{{ params.ariaLabel }}">
<ul class="patternlib-subnav__list" aria-label="{{ params.ariaListLabel }}" role="menubar">
{% for item in params.items %}
<li class="patternlib-subnav__item {{ ' patternlib-subnav__item--active' if (item.path == params.currentPath) or (item.path in params.currentPath) }}">
<a href="{{ item.path }}" class="patternlib-subnav__link" role="menuitem">{{ item.title }}</a>
<li class="patternlib-subnav__item {{ ' patternlib-subnav__item--active' if (item.url == params.currentPath) or (item.url in params.currentPath) }}">
<a href="{{ item.url }}" class="patternlib-subnav__link" role="menuitem">{{ item.title }}</a>
{% if item.anchors %}
<ul class="patternlib-subnav__sub-items">
{% for anchor in item.anchors %}
<li class="patternlib-subnav__item">
<a href="{{ anchor.path }}" class="patternlib-subnav__link" role="menuitem">{{ anchor.title }}</a>
<a href="{{ anchor.url }}" class="patternlib-subnav__link" role="menuitem">{{ anchor.title }}</a>
</li>
{% endfor %}
</ul>
Expand Down

0 comments on commit 4024ffe

Please sign in to comment.