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 b34d0fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 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?.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,
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
4 changes: 2 additions & 2 deletions test/lib/filters/items-from-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('itemsFromNavigation filter', () => {
}])
})

it('Converts navigation data to items array using path prefix', () => {
it.skip('Converts navigation data to items array using path prefix', () => {
const config = {
pathPrefix: '/prefix/'
}
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('itemsFromNavigation filter', () => {
}])
})

it('Converts navigation data to items array adding parent site and using path prefix', () => {
it.skip('Converts navigation data to items array adding parent site and using path prefix', () => {
const config = {
parentSite: {
url: 'https://example.org',
Expand Down

0 comments on commit b34d0fd

Please sign in to comment.