From 7c62190a1a6c2c8ccd9404ba1e447ccc54a0edbd Mon Sep 17 00:00:00 2001 From: lhokktyn <810615+lhokktyn@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:54:24 +0000 Subject: [PATCH] refactor: allow missing nav items When the "eleventyExcludeFromCollections" option is enabled, the "collections.all" array will not contain all pages, resulting in eleventyNavigationBreadcrumb() throwing a "Node does not exist" exception, which manifests as an opaque nunjucks error that is difficult for the reader to trace. This change uses the "allowMissing" option of eleventyNavigationBreadcrumb() to effectively allow this scenario to fail silently (no breadcrumb will appear at all rather than failing to compile). --- layouts/base.njk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts/base.njk b/layouts/base.njk index 3d4e5bd..42272fa 100644 --- a/layouts/base.njk +++ b/layouts/base.njk @@ -13,7 +13,7 @@ {% set pageCount = pagination.pages | length %} {# Navigation #} -{% set breadcrumbItems = collections.all | eleventyNavigationBreadcrumb(eleventyNavigation.key, { includeSelf: includeInBreadcrumbs }) | itemsFromNavigation(page.url, options) if eleventyNavigation.key %} +{% set breadcrumbItems = collections.all | eleventyNavigationBreadcrumb(eleventyNavigation.key, { includeSelf: includeInBreadcrumbs, allowMissing: true }) | itemsFromNavigation(page.url, options) if eleventyNavigation.key %} {% set minimumItemsInBreadcrumbs = 0 %} {% set minimumItemsInBreadcrumbs = 1 if options.parentSite %} {% set showBreadcrumbs = options.showBreadcrumbs != false and breadcrumbItems | length > minimumItemsInBreadcrumbs %}