Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow missing breadcrumb navigation items #352

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

lhokktyn
Copy link
Contributor

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).

In our case, we use eleventyExcludeFromCollections to exclude some dynamically generated pages from collections.all for performance reasons.

We're using 11ty v3.0.0, but allowMissing is a valid option for eleventyNavigation@0.3.5.

@paulrobertlloyd I figured this would be a relatively safe option to hardcode into the base template, but do you think it warrants exposing as an option to consumers of this plugin?

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).
@paulrobertlloyd
Copy link
Collaborator

@lhokktyn Thanks for this. This would certainly prevent the annoying and opaque errors that are too often a side-effect of eleventyNavigation.

I’d be tempted to add to base template as you have here, and make it an option later should that be needed.

Will take a closer look some time later this week, along with the order of searchPaths, and hopefully put together a minor release with these 2 changes.

@paulrobertlloyd paulrobertlloyd changed the title refactor: allow missing nav items Allow missing breadcrumb navigation items Nov 20, 2024
@paulrobertlloyd paulrobertlloyd merged commit 3be0ff3 into x-govuk:main Nov 20, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants