Nanoc Plugin for Global Content Captures
I use Nanoc, a Ruby static website generator. It is pretty nice and has all the features I need for generating this site. One feature that was missing, however, was the ability to capture content on one page and use it on others. I manage the archive links as a page and the page content is inserted in the left nav bar using the site's layout template. I also reuse my resume content on the printable version of the page.
After inquiring on the Nanoc mail list, I came up with the following hack to solve my problem. Just add the code at the bottom of the page to a .rb file in your lib directory and then you can use it as follows.
<% global_content_for :foo do %>
This is the FOO stuff.
<% end %>
In any page you want to see the :foo content, just use markup like the following.
<%= global_content_for :foo %>
I wrote in a rudimentary ability to detect that one or more pages has unsatisfied global references. This situation arises pretty much whenever you use nanoc to do an update compile. In this case, nanoc will raise an exception with a message that there are unsatisfied global references. The "workaround" is to ensure that you are recompiling not only the pages that print out the global capture, but also the pages where the global capture is made. Because I have so few pages, it is not a problem for me to just recompile the whole site.
The real solution to this problem is smarter dependency resolution. It should be possible in a page's metadata to mark a page as dependent on some other page. If a page were being recompiled, all it's dependencies would be recompiled as well. If Nanoc can't handle it, maybe one of the other static website generators such as Webby will be able to handle it.
The Code
Add this to a file in your site's lib directory, say lib/global_capturing.rb: