From 86bdfa0daab3638cf4e2ba9fde2de0db44e54b87 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Tue, 12 Dec 2023 00:11:35 +0000 Subject: [PATCH] Add navigation option --- components/header/template.njk | 6 ++++++ index.js | 1 + lib/filters/current-page.js | 13 +++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 lib/filters/current-page.js 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 72945f5e..91a8dcd6 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,7 @@ module.exports = function (eleventyConfig, pluginOptions = {}) { // Filters 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..bf52ee14 --- /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 + }) +}