Blogging extra helper - aadlani/nanoc-toolbox GitHub Wiki
http://rubydoc.info/github/aadlani/nanoc-toolbox/Nanoc/Toolbox/Helpers/BloggingExtra
In the folder lib/helpers_.rb
add the Helper inclusion as following:
# Helpers of the nanoc-toolbox
include Nanoc::Toolbox::Helpers::BloggingExtra
Enable blog post behavior on an item. No real need outside the lib, used internally by add_post_attributes
(see bellow)
Example:
items.each do |item|
act_as_post(item)
end
Enable blog post behavior on all the items located in the post folder(s) defined in your config file (default: ['_posts', '_articles']).
Example:
# In your config.yaml
post_dirs: [ 'posts' ]
# In your Rules file
preprocess do
add_post_attributes
end
Returns the list of posts grouped by years and months in a hash.
posts_by_date # => { 2011 => { 12 => [item0, item1], 3 => [item0, item2]}, 2010 => {12 => [...]}}
Example:
<% posts_by_date.each do |year, months_values| %>
<h2><%= year %></h2>
<% months_values.each do |month, posts| %>
<h3><%= Date.parse("#{year}-#{month}-01").strftime("%B %Y") %></h3>
<ul>
<% posts.each do |article| %>
<li><%= link_to article[:title], article %></li>
<% end %>
</ul>
<% end %>
<% end %>
Returns n number of recent posts, optionally omits the current one
Example:
<% recent_posts(4).each do |rp| %>
<div class="span4">
<h5><%= link_to rp[:title], rp, :title => rp[:title] if rp[:title] %></h5>
<p><%= rp[:summary] %></p>
</div>
<% end %>
Get an item's slug if it has one, or use its filename sans extension
Examples:
# item[:filename] = "abc def geh.html"
slug_for(item) # => "abc-def-geh"