Skip to content

Commit

Permalink
Add navigation option
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Dec 19, 2023
1 parent 451953f commit 375d444
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions components/header/template.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{%- from "x-govuk/components/primary-navigation/macro.njk" import xGovukPrimaryNavigation -%}
{%- from "../site-search/macro.njk" import appSiteSearch -%}
{%- set headerType = "no-border" if
layout == "product" or
layout == "collection"
-%}
{%- set headerType = "full-width-border" if params.navigation -%}
<header class="govuk-header app-header{% if headerType %} app-header--{{ headerType }}{% endif %}" role="banner" data-module="govuk-header">
<div class="govuk-header__container govuk-width-container app-header__container">
<div class="govuk-header__logo app-header__logo">
Expand All @@ -26,3 +28,7 @@
{{ appSiteSearch(params.search) if params.search.indexPath | indent(4) }}
</div>
</header>
{{ xGovukPrimaryNavigation({
visuallyHiddenTitle: params.navigation.visuallyHiddenTitle,
items: params.navigation.items | currentPage(page.url)
}) if params.navigation }}
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module.exports = function (eleventyConfig, pluginOptions = {}) {
require('./lib/filters/canonical-url.js')
)
eleventyConfig.addFilter('date', require('./lib/filters/date.js'))
eleventyConfig.addFilter(
'currentPage',
require('./lib/filters/current-page.js')
)
eleventyConfig.addFilter('includes', require('./lib/filters/includes.js'))
eleventyConfig.addFilter(
'itemsFromCollection',
Expand Down
13 changes: 13 additions & 0 deletions lib/filters/current-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Indicate which is the current item in navigation items
* @param {Array} array - Navigation items
* @param {string} pageUrl - URL of current page
* @returns {Array} Navigation items
*/
module.exports = (array, pageUrl) => {
return array.map((item) => {
item.current = pageUrl.startsWith(item.href)

return item
})
}

0 comments on commit 375d444

Please sign in to comment.