John Guidry avatar John Guidry committed fb97bac

Clarify routing.

Comments (0)

Files changed (4)

 end
 
 compile '/posts/*', :rep => :summary do
-  filter :haml
+  filter_markup_by_ext(item) 
   filter :colorize_syntax
-  layout 'post_summary'
-end
-
-compile '/posts/*' do
-  filter :haml
-  filter :colorize_syntax
-  layout 'post'
-  layout 'default'
+  layout 'post_summary' 
 end
 
 compile '*' do
-  filter :haml
-  layout 'default'
+  filter_markup_by_ext(item) 
+  filter :colorize_syntax
+  layout 'default' 
 end
 
 route '/assets/css/*/' do
    item.identifier.chop + '.css'
 end
 
-route '/posts/*', :rep => :summary do
-  nil # Don't create files for summaries
+# Don't create output of the post summary rep
+route 'posts/*', :rep => :summary do
+  nil
 end
 
 route '*' do
-  item.identifier + 'index.html'
+  route_path(item)
 end
 
-layout '*', :haml
+# For now all layouts are in haml
+layout '*', :haml, :format => :html5

content/index.haml

 --- 
-title: A Novel Spin 
+title: a novel spin 
 ---
 
 - @site.sorted_articles[0, 5].each do |post|

layouts/default.haml

 %html{html_attrs()}
   %head
     %meta{:charset =>'utf-8'} 
+    %meta{:name => 'generator', :content => 'nanoc 3.1.7'}
     %title a novel spin 
     %link{:rel =>'stylesheet', 
           :type =>'text/css', 
     %link{:rel => 'stylesheet',
           :type => 'text/css',
           :href => 'http://fonts.googleapis.com/css?family=Droid+Sans&v1'}
-    %meta{:name => 'generator', :content => 'nanoc 3.1.7'}
   %body
     #header
       %h1
       #sub-header
         %hr
       #content
-        = yield
+        ~ yield
 include Nanoc3::Helpers::Tagging
 include Nanoc3::Helpers::Text
 
+#
 # Nabbed at http://starrhorne.com/posts/howto_build_a_blog_with_nanoc/
+#
 class Nanoc3::Item
-  def content(opts = {})
-    opts[:rep] ||= :default
-    opts[:snapshot] ||= :last
+  def content(opts = {})                                                       
+    opts[:rep] ||= :default                                                    
+    opts[:snapshot] ||= :last                                                  
     reps.find { |r| r.name == opts[:rep] }.content_at_snapshot(opts[:snapshot])
   end
 
     identifier.split("/").last 
   end
 end
+
+#
+# Next two nicked from https://github.com/unthinkingly/unthinkingly-blog
+#
+def filter_markup_by_ext(item)
+  # item[:extension] returns 'html.erb' for multi-dotted filename
+  ext = item[:extension].nil? ? nil : item[:extension].split('.').last
+
+  if ext == 'erb'
+    filter :erb
+  elsif ext == 'haml' || ext.nil?
+    filter :haml
+  elsif ext == 'html'
+  else
+    raise "Filter is not configured for #{item.identifier} in Rules file."
+  end
+end
+
+def route_path(item)
+  # in-memory items have not file
+  return item.identifier + "index.html" if item[:content_filename].nil?
+       
+  url = item[:content_filename].gsub(/^content/, '')
+          
+  # determine output extension
+  extname = '.' + item[:extension].split('.').last
+  outext = '.haml'
+  if url.match(/(\.[a-zA-Z0-9]+){2}$/) # => *.html.erb, *.html.md ...
+    outext = '' # remove 2nd extension
+  elsif extname == ".sass"
+    outext = '.css'
+  else
+    outext = '.html'
+  end
+
+  url.gsub!(extname, outext)
+end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.