1. Sean Davis
  2. nanocHome

Source

nanocHome / Rules

#!/usr/bin/env ruby

# A few helpful tips about the Rules file:
#
# * The order of rules is important: for each item, only the first matching
#   rule is applied.
#
# * Item identifiers start and end with a slash (e.g. "/about/" for the file
#   "content/about.html"). To select all children, grandchildren, ... of an
#   item, use the pattern "/about/*/"; "/about/*" will also select the parent,
#   because "*" matches zero or more characters.
preprocess do
  def stuff1
    @tags = {}
    blogarticles = items.select { |i| i[:kind] == 'article' }
    blogarticles.each do |b|
      b[:tags].each do |tag|
        @tags[tag]=1
      end
    end
    @taglist = []
    @tags.each do |tag,val|
      @taglist << tag
      @items << Nanoc3::Item.new(
                                 "<%= render 'tag_page' %>",
                                 {:title => "Items tagged with #{tag}",
                                  :tag   => tag },
                                 "/blog/tag/#{tag}/"
                                 )
    end
    @site.config['tags']=@taglist
  end

  stuff1
end

compile '/assets/*/' do
  #nothing
end

route '/assets/*/' do
  item.identifier.chop
end


route '/sitemap/' do
  item.identifier.chop + '.xml'
end

compile '/sitemap/' do
  filter :erb
end

layout '/tag_page/', :erb

compile '/blog/tag/*/' do
  filter :erb
  layout '/blog/'
  layout '/default/'
  filter :relativize_paths, :type => :html
end

compile '/css/*/' do
  filter :relativize_paths, :type => :css
  # don't filter or layout
end

compile '/tutorials/biowulf-2011/images/*' do
  # don't filter or layout
end

route '/tutorials/biowulf-2011/images/*' do
  item.identifier.chop + ".jpg"
end

compile '/js/*' do
  #nothing
end
  
route '/js/*/' do
  item.identifier.chop + ".js"
end

compile '/images/*' do
  #nothing
end
  
route '/images/*/' do
  item.identifier.chop + "." + item[:extension]
end

compile '/blog/' do
  filter :erb
  layout 'blog_index'
  layout 'default'
  filter :relativize_paths, :type => :html
end

compile '/blog/feed/' do
  filter :erb
end

route '/blog/feed/' do
  '/blog/feed.xml'
end

route '/blog/*', :rep => :summary do
  nil # Don't create files for summaries
end

compile '/blog/*', :rep => :summary do
  rep.filter :erb
  rep.layout 'post_summary'
end

compile '/blog/*' do
  filter :erb unless item.binary?
  if item[:extension] == 'rst'
    filter :rst
  end
  if item[:extension] == 'md'
    filter :kramdown
  end
  filter :colorize_syntax, :colorizers => { 
      :ruby => :pygmentize, 
      :r => :pygmentize}
  layout 'post' unless item.binary?
  layout 'blog' unless item.binary?
  layout 'default' unless item.binary?
  filter :relativize_paths, :type => :html unless item.binary?
end


compile '*' do
  if item[:extension] == 'org'
    filter :org
  end
  filter :erb unless item.binary?
  layout 'default' unless item.binary?
  filter :relativize_paths, :type => :html unless item.binary?
end

route '/css/*' do
  item.identifier.chop + ".css"
end

route '*' do
  if item.binary? 
      item.identifier.chop + '.' + item[:extension]
  else
      item.identifier + 'index.html'
  end
end

layout '*', :erb