From 3acd5918faff475d71cca7f4dab3404da2082118 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Tue, 12 Dec 2023 23:42:54 +0000 Subject: [PATCH] No longer need to use url helper in itemsFromNavigation filter --- lib/filters/items-from-navigation.js | 15 ++--- test/lib/filters/items-from-navigation.js | 69 ----------------------- 2 files changed, 6 insertions(+), 78 deletions(-) diff --git a/lib/filters/items-from-navigation.js b/lib/filters/items-from-navigation.js index 2baf5268..31be7ed6 100644 --- a/lib/filters/items-from-navigation.js +++ b/lib/filters/items-from-navigation.js @@ -1,4 +1,3 @@ -const url = require('@11ty/eleventy/src/Filters/Url.js') const smart = require('./smart.js') /** @@ -10,21 +9,19 @@ 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), + 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 @@ -32,7 +29,7 @@ module.exports = (eleventyNavigation, pageUrl = false, options = {}) => { // 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) diff --git a/test/lib/filters/items-from-navigation.js b/test/lib/filters/items-from-navigation.js index f421b7d5..aa9d869d 100644 --- a/test/lib/filters/items-from-navigation.js +++ b/test/lib/filters/items-from-navigation.js @@ -98,37 +98,6 @@ describe('itemsFromNavigation filter', () => { }]) }) - it('Converts navigation data to items array using path prefix', () => { - const config = { - pathPrefix: '/prefix/' - } - const result = itemsFromNavigation(eleventyNavigationBreadcrumb, '/parent/child', config) - - assert.deepEqual(result, [{ - href: '/prefix/', - text: 'Home', - current: false, - parent: true, - children: false - }, { - href: '/prefix/parent/', - text: 'Parent page', - current: false, - parent: true, - children: [{ - href: '/prefix/parent/child/', - text: 'Child page', - current: false - }] - }, { - href: '/prefix/parent/child', - text: 'Child page', - current: true, - parent: true, - children: false - }]) - }) - it('Converts navigation data to items array adding parent site', () => { const config = { parentSite: { @@ -165,42 +134,4 @@ describe('itemsFromNavigation filter', () => { children: false }]) }) - - it('Converts navigation data to items array adding parent site and using path prefix', () => { - const config = { - parentSite: { - url: 'https://example.org', - name: 'Example' - }, - pathPrefix: '/prefix/' - } - const result = itemsFromNavigation(eleventyNavigationBreadcrumb, '/parent/child', config) - - assert.deepEqual(result, [{ - href: 'https://example.org', - text: 'Example' - }, { - href: '/prefix/', - text: 'Home', - current: false, - parent: true, - children: false - }, { - href: '/prefix/parent/', - text: 'Parent page', - current: false, - parent: true, - children: [{ - href: '/prefix/parent/child/', - text: 'Child page', - current: false - }] - }, { - href: '/prefix/parent/child', - text: 'Child page', - current: true, - parent: true, - children: false - }]) - }) })