Skip to content

Commit

Permalink
No longer need to use url helper in itemsFromNavigation filter
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Dec 12, 2023
1 parent 74f805b commit 9607dcf
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/filters/items-from-navigation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const url = require('@11ty/eleventy/src/Filters/Url.js')
const smart = require('./smart.js')

/**
Expand All @@ -10,29 +9,27 @@ const smart = require('./smart.js')
* @returns {Array} `items` array
*/
module.exports = (eleventyNavigation, pageUrl = false, options = {}) => {
const pathPrefix = options?.pathPrefix || '/'
const currentUrl = pageUrl ? url(pageUrl, pathPrefix) : false
const items = []

eleventyNavigation.forEach(item => {
const isCurrentPage = pageUrl && url(item.url, pathPrefix) === currentUrl
const isCurrentPage = pageUrl && item.url === pageUrl
const navItem = {
current: isCurrentPage,
parent: pageUrl ? pageUrl.startsWith(item.url, pathPrefix) : false,
href: url(item.url, pathPrefix),
parent: pageUrl ? pageUrl.startsWith(item.url) : false,
href: item.url,
text: smart(item.title),
children: item.children
? item.children.map(child => ({
current: pageUrl ? url(child.url, pathPrefix) === currentUrl : false,
href: url(child.url, pathPrefix),
current: pageUrl ? child.url === pageUrl : false,
href: child.url,
text: smart(child.title)
}))
: false
}

// If the current page is being shown in the navigation, do not link to it
if (!isCurrentPage) {
navItem.href = url(item.url, pathPrefix)
navItem.href = item.url
}

items.push(navItem)
Expand Down

0 comments on commit 9607dcf

Please sign in to comment.