pablomartinezalvarez / glayu

A static site generator for mid-sized sites.
MIT License
79 stars 4 forks source link

get_parents function for getting parents by node keys #16

Closed gnucifer closed 6 years ago

gnucifer commented 6 years ago

Hi again! I'm attempting to implementing breadcrumbs on the site I'm working on, and found it necessary to implement some kind of way of getting all parents of a node. Since I'm a little bit inexperienced I'm not sure if there are better ways of solving this issue, but this is my attempt at providing at least the basics. Sorry for not providing any tests, I might try to add some later.

gnucifer commented 6 years ago

Also added a basic test.

pmartinezalvarez commented 6 years ago

Hi! Thanks so much :) I will merge your commits.

But please check the usage of categories to generate the breadcrumbs. It is how it is done on the glayu times theme page.eex

<ul class="categories">
  <%= for category <- @page.categories do %>
      <li><a href="<%= category.path %>" class="category"><span><%= category.name %></span></a></li>
   <% end %>
</ul>
gnucifer commented 6 years ago

Hi! Yes I now realize that I would have been able to just fetch the first post and get the breadcrumbs from there, also on category pages (which was my problem), so thank you for clearing that up for me. :) But nice of you to merge it anyway.

EDIT: Aha, no that would not work without some extra processing as I could also get subcategories that is not active for the current category page. But I would have been able to intersect the post categories with the category page's category keys to get breadcrumbs for category pages.