-
Notifications
You must be signed in to change notification settings - Fork 8
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
generate multi-level menus #4
Comments
I'm now sure that the generated html is not always correct. If you have the following headings : var headings = [
{ id: "foo1", tag: "h1", text: "foo1 text" },
{ id: "foo2", tag: "h2", text: "foo11 text" }
]; My JSFiddle example will generate the following html : <!-- toc -->
<div class="col-md-3">
<div class="sidebar hidden-print affix-top toc" role="complementary">
<ul class="nav sidenav">
<li></li><li><a href="#foo1">foo1 text</a></li>
<li><a href="#foo2">foo2 text</a>
</div>
</div> You can notice the useless <li><a href="#foo1">foo1 text</a></li> You can also notice the missing <li><a href="#foo2">foo2 text</a></li></ul> I definetly have to find a smarter way to generate my menu. Any help gladly welcome ! Maybe @hegemonic (who is the author of the pull request that adds the tag level to metadata : #1) has an idea on this... |
In addition, the second flaws mentionned in my first comment annoys me a lot :
I'm pretty sure that I'm using Handlebars helpers the wrong way. Here again, any help gladly welcome ! |
The problem in your JSFiddle seems to be that you're outputting a And it seems like the headings output should be available somewhere in Hope that helps. If I think of anything else or get a break to look at the issue, I'll follow up. (Or maybe it spurs some ideas for others who can jump in.) |
My problem is that I need to close the I need to do that because I'm not closing And that's because I need to leave the And unfortunately, I don't get your point about |
As far as I can see, the list of headings is ordered by tags, like this: var headings = [
{ id: "foo1", tag: "h1", text: "foo1 text" },
{ id: "foo2", tag: "h1", text: "foo2 text" },
{ id: "foo3", tag: "h1", text: "foo3 text" },
{ id: "foo11", tag: "h2", text: "foo11 text" },
{ id: "foo12", tag: "h2", text: "foo12 text" }
]; To generate a multi-level menu, the list of headings should preserve the ordering. |
Problem fixed using a fork: xiphiaz/metalsmith-headings (see this message). This plugin could be fixed when pull request #5 will be merged. |
Very good news, thanks a lot! |
There are many examples on the web on how to generate multi-level menus with handlebars. The problem is that they are often based on the following data structure :
As you can see, submenus are embedded in their parent menu.
metalsmith-headings generates a flat data structure :
It is then harder to generate a correct menu with handlebars.
I'd like to get something like this in html :
As you can see, sublist
ul
is embedded in its parentli
.I manage to start something that works a little bit. But there is large flaws to improve. I'm not an expert in js, nor in handlebars. You can see a working test the following JSFiddle example.
Mains flaws are :
Feel free to share your thinking, to improve my solution, and to discuss about the data structure that metalsmith-headers should generate.
The text was updated successfully, but these errors were encountered: