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

Auto-generated nested navigation #243

Closed
hugodessomme opened this issue Jul 28, 2015 · 3 comments
Closed

Auto-generated nested navigation #243

hugodessomme opened this issue Jul 28, 2015 · 3 comments

Comments

@hugodessomme
Copy link

Hello,

I would like in a column to display navigation of each element. My problem is some of my element have a parent, and I would in the generated navigation that it would create a sub navigation to the parent element.

For example :

/*doc

---
title: parent
name: parent
category: test

---
*/

...

/*doc

---
title: child
name: child
parent: parent

---
*/

output (what I want):

<ul>
   <li>
      <a href="#parent">parent</a>
      <ul>
         <li>
            <a href="#child">child</a>
         </li>
      </ul>
   </li>
</ul>

I know my code is wrong but for now I just copied the one in the hologram example project (header.html):

<ul class="list-group">
   <% @blocks.each do |block| %> 
      <li class="list-group-item">
         <a href="#<%= block[:name] %>"><%= block[:title] %></a>
      </li>
   <% end %>
</ul>

Help, anyone?
Thank you!

@rishabh-ink
Copy link
Contributor

Hi @hugodessomme, this is possible by modifying the header.html in the following way. You can see this in action in the example of the Cortana theme. Here's a snippet from Cortana's _header.html:

<% catWrappers = Array.new %>
<% @categories.each do |cat| %>
  <% catWrapperName = cat[0].split(nameScope).first %>
  <% if not catWrappers.include?(catWrapperName) %>
    <% catWrappers.push(catWrapperName) %>
  <% end %>
<% end %>

<nav class="cortana-nav">
  <ul>
    <% if file_name.include?('index.html') %>
      <li><a class="active" href="index.html">Home</a></li>
    <% else %>
      <li><a href="index.html">Home</a></li>
    <% end %>
  </ul>
  <% catWrappers.each do |wrapper| %>
    <h3><%= wrapper %></h3>
    <ul>
    <% @categories.each do |cat| %>
      <% if cat[0].include?(wrapper) %>
        <% catName = cat[0].split(nameScope).last %>
        <% if catName == title.split(nameScope).last %>
          <li><a class="active" href="<%= cat[1] %>"><%= catName %></a></li>
        <% else %>
          <li><a href="<%= cat[1] %>"><%= catName %></a></li>
        <% end %>
      <% end %>
    <% end %>
    </ul>
  <% end %>
</nav>

In your hologram_config.yml file, you'd need to add:

name_scope: ' - '

The string - is used to separate the parent and child components in the category property. Finally, in your documentation, you'd need to use it as:

/*doc
---
title: Small text
name: typography-small-text
category: Scaffolding - Typography
---
*/
...
/*doc
---
title: Strong text
name: typography-strong-text
category: Scaffolding - Typography
---
*/

As you can see, each component needs to have a parent (in the above example, Scaffolding).

You can also give the Cortana theme a try, which support nested categories out of the box.

@hugodessomme
Copy link
Author

I will give it a try! Thank you :)

@jdcantrell
Copy link
Contributor

Closing this, you can do what you're looking for with more ruby code in the header.html or as @rishabhsrao using the Cortana theme (which is the same method but packaged up for you)

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

No branches or pull requests

3 participants