Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add navigation option #220

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -27,6 +27,10 @@ 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',
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
})
}