Get page hierarchical structure for breadcrumbs #351
Unanswered
simplerethink
asked this question in
Q&A
Replies: 1 comment 1 reply
-
That would be a nice plugin, and I think it wouldn't be hard. The So I imagine something like this should work: import { Page, Directory } from "lume/core.ts";
interface Link {
text: string;
url: string;
}
function getBreadcrumb(page: Page) {
const links: Link[];
let currentDirectory = page.parent;
while (currentDirectory) {
const indexPage = currentDirectory.pages.get("index.md");
links.push({
text: indexPage.data.title,
url: indexPage.data.url
});
currentDirectory = currentDirectory.parent;
}
return links;
} You can use this helper in your templates: <ol>
{% for item in getBreadcrumb(page) %}
<li>
<a href="{{ item.url }}">{{ item.text }}</a>
</li>
{% endfor %}
</ol> |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a file structure similar to this:
How can I generate breadcrumbs in Lume?
For example, in
post2.md
I'd like to have output like:For
post1.md
I'd like to have output:Basically, I'm looking to fetch the hierarchical structure of a page based on the position within the file structure. I have dozens of categories, so I'm looking for a dynamic way of doing this within the template.
Beta Was this translation helpful? Give feedback.
All reactions