diff --git a/components/header/template.njk b/components/header/template.njk index 4de4f029..2775f643 100644 --- a/components/header/template.njk +++ b/components/header/template.njk @@ -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 -%} +{{ xGovukPrimaryNavigation({ + visuallyHiddenTitle: params.navigation.visuallyHiddenTitle, + items: params.navigation.items | currentPage(page.url) +}) if params.navigation }} diff --git a/index.js b/index.js index 8e6371e5..2621a299 100644 --- a/index.js +++ b/index.js @@ -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', diff --git a/lib/filters/current-page.js b/lib/filters/current-page.js new file mode 100644 index 00000000..aab778b5 --- /dev/null +++ b/lib/filters/current-page.js @@ -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 + }) +}