Closed jonw-cogapp closed 4 years ago
I've been trying to get breadcrumb navigation to work as well, and have been running into the same issue. I tried doing some debugging on my own, and have come to the conclusion that the pages getting passed into the findDependencies function are always empty.
After some cursory print debugging, it looks like the findDependencies function is being called before findNavigationEntries resolves. Here's what my logs look like: Nodes passed to findDeps: [] Nodes passed to findDeps: [] Nodes passed to findDeps: [] Nodes passed to findDeps: [] Nodes passed to findDeps: [] Nodes passed to findDeps: [] Nodes passed to findDeps: [] Nodes passed to findDeps: [] Nodes passed to findDeps: [] Nodes passed to findDeps: [] Nodes passed to findDeps: [] Entry to pages: { key: 'COVID-19', parent: 'main', order: 1, url: '/', pluginType: 'eleventy-navigation', parentKey: 'main', title: 'COVID-19', children: [] } Entry to pages: { key: 'Fall Plans', parent: 'main', order: 2, url: '/plans/', pluginType: 'eleventy-navigation', parentKey: 'main', title: 'Fall Plans', children: [] } Entry to pages: { key: 'FAQ', parent: 'main', order: 3, url: '/faq/', pluginType: 'eleventy-navigation', parentKey: 'main', title: 'FAQ', children: [] } ...
And the relevant console logs in the code:
function findNavigationEntries(nodes = [], key = "") { ... return pages.sort(function(a, b) { return (a.order || 0) - (b.order || 0); }).map(function(entry) { if(!entry.title) { entry.title = entry.key; } if(entry.key) { entry.children = findNavigationEntries(nodes, entry.key); } console.log("Entry to pages: ", entry); return entry; }); }
function getDependencyGraph(nodes) { let pages = findNavigationEntries(nodes); let graph = new DepGraph(); console.log("Nodes passed to findDeps: ", pages); findDependencies(pages, graph); return graph; }
Edit: sorry, I misread your comment. Does this work for you on the standard nav output?
I did a bit more digging yesterday and it seems that it's eleventyNavigation
(findNavigationEntries
) that's taking a full collection and always returning an empty array. I didn't get much further than that though
@jonw-cogapp Yes, the standard nav output runs just fine for me.
I'm closing this issue - I'd accidentally botched the keys in the example I'd linked and this was the root cause of this issue. We've had a heatwave here so I'm blaming that 😅
When I realised this and looked at my real project code there was another reason; the indentation was using a tab instead of spaces (which is weird because I don't use tabs). That was what prevented it from picking up the keys there.
I've cloned and ran the sample in this repo, and it produces the results navigation just fine. However when I tried to implement the basic mammals example externally there is some kind of error preventing the navigation from being output. I've spent a while scratching my head on this and I just can't see where I'm going wrong. The collection and the navigation plugin both seem to be being picked up, but there is no output and the breadcrumb causes an error message.
The code I'm running: https://github.com/jonw-cogapp/11ty-navigation
Output from the log filter on
collections.all
Error message
Debug output