-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
Does Eleventy support preserving nested folder structure in template loops? #1171
Comments
Of course, kinda selling my own work... But you could try the Ancestry plugin. I started it exactly for that kind of "problems". |
I’m assuming you’ve seen the navigation plugin too? Is there a reason you can’t use that here? https://www.11ty.dev/docs/plugins/navigation/ |
Actually, I hadn't seen that. Thanks for both your responses guys! Much appreciated. |
Wondering if there's a more automatic way of achieving this using the Navigation plugin, without having to declare Looking at the Real World example's use of For example, is this ludicrous? Achieves what we're after in terms of structured output/order in navigation based on folder structure, but feels a bit dirty and brittle: // eleventyComputed.js
module.exports = {
eleventyNavigation: {
key: data => {
// Get URL path fragments
const urlParts = data.page.url.split('/');
// Taking all but first and last leaves us with the page path to use as key
const pathDirs = urlParts.slice(1, urlParts.length - 1);
const path = pathDirs.join('/');
return data.key || path;
},
title: data => data.title,
parent: data => {
// Get URL path fragments
const urlParts = data.page.url.split('/');
// Taking all but first and last two leaves us with the parent directory path
const parentDirs = urlParts.slice(1, urlParts.length - 2);
const parent = parentDirs.join('/');
// If no parent specified, try to use the automatic fallback
// Because this is also based on URL paths, keys and parents should automatically match as needed
return data.parent || parent;
},
order: data => data.order
}
}; |
@adamduncan Do you have a more elaborate example of that in a repo? Would love to see it in full glory 🙂 |
@marksdk — Have put together a demo repo here: https://github.com/adamduncan/eleventy-auto-navigation I hope you and others find it helpful. |
@adamduncan Thanks so much for the repo! I'll definitely check it out 👍 |
I have a somewhat nested folder structure like this:
I want to build a navigation sidebar for my documentation-style site that mirrors the nested structure of the directory.
Is there a way to do this in 11ty? From what I've seen, Collections work on nested directories but completely flatten them.
The text was updated successfully, but these errors were encountered: