tek, thinks & la strada ☯ॐ☢ csmr@kapsi

An index of posts for Nanoc 4-blog

Let's implement a simple side-menu containing the content items on our site, an index of posts.

After reading nanoc.ws and stoneship -repos on github, a lot of sillyness with a separate sidebar -layout and html - and couple of hours of trial...

I finally have the insight. First: I moved all the posts into /content/posts/ -directory, and the javascript and css into /content/res/. I Think this may be a good approach for many blog-sites. It may make rendering and filtering the content easier.

Then, added the template below to layouts/default.html - to render a link-list to the posts into the sidemenu, sorted by datetime, :

  <ul>
    <li>
          <a href="./">Home</a>
    </li>
    <% @uitems = @items.find_all('/posts/*').sort_by {|i| i[:datetime] } %> 
    <% @uitems.reverse_each do |item| %>
        <li>
          <a href=".<%= item.path %>"><%= item[:title] %></a>
        </li>
    <% end %>
  </ul>

And then I added a filter :erb in Rules, so that the compile rule for posts is:

compile '/posts/*.html' do
  filter :erb
  write item.identifier.to_s
end

As you can see on this page (to the right) - it works, and also sorts the items in reverse date order, but crashes if the items do not contain datetime-field in the yml-header. One could also use some other yml-field for sorting, even add a sort-index -field used only for sorting within a erb template.

Well it that wasn't as smooth and pleasant and super quick as I had hoped for 8). - Its the usual: the concepts and ideas behind a solution are bit of "hebrew" to me. Well at least I have a working content-template, time to polish the sidemenu css-styles.

Copyright C. P. - Last Updated - All Rights Reserved - Ask permission to republish.