I'm building a static generator for a getting started guide and I am grouping pages for the same guide into a folder.
how would I add a footer to the bottom of the generated pages for next and previous pages?
I'm building a static generator for a getting started guide and I am grouping pages for the same guide into a folder.
how would I add a footer to the bottom of the generated pages for next and previous pages?
Pages (“items“) in Nanoc do not have an intrinsic ordering, and there is thus no concept of “previous” and “next” unless you add one. There are ways to introduce an ordering to a list of items, though:
@items.sort_by { |i| i[:title] })@items.sort_by { |i| i.fetch(:order, 0) })Once there is an ordering defined for a collection of items, you can use
#indexto find out the index of the current page, and thus also the indices of the previous and next pages. For example, assuming thatordered_itemsis the list of ordered items:A
#next_itemfunction would be similar.How the
#ordered_itemsfunction is implemented, depends on what you would like to achieve. Do you want to order all items on the site? If so, an implementation could look like this:If, on the other hand, you’d prefer the ordered items to be scoped to a certain section of the site, you could have an implementation like
With the ChildParent helper, you could determine the ordered items for the current section automatically:
Finally, in the footer (e.g. in the default layout), you could stick something like
and then you’d have a link to the previous page. Similar for the next link.