Skip to content

Commit

Permalink
refactor: allow missing nav items
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
lhokktyn authored and paulrobertlloyd committed Nov 20, 2024
1 parent 95db584 commit 3be0ff3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit 3be0ff3

Please sign in to comment.