Permalink
Browse files

Add a sitemap extension

  • Loading branch information...
1 parent 14eca01 commit 9fa91e12477ff349163a691f498792c9e855ae37 @lance lance committed Nov 15, 2011
View
1 1x/builds/index.html.haml
@@ -1,6 +1,7 @@
---
title: Incremental Builds
layout: default
+change_frequency: daily
---
%script{:type=>'text/javascript', :src=>'/javascripts/jenkins.js'}
View
1 2x/builds/index.html.haml
@@ -1,6 +1,7 @@
---
title: 2.x Incremental Builds
layout: default
+change_frequency: hourly
---
%script{:type=>'text/javascript', :src=>'/javascripts/jenkins.js'}
View
1 2x/gem-repo/index.html.haml
@@ -1,6 +1,7 @@
---
title: RubyGems Repo
layout: gems
+change_frequency: hourly
---
%script{:type=>'text/javascript', :src=>'/javascripts/jquery.js' }
View
1 _config/site.yml
@@ -14,7 +14,6 @@ profiles:
path: /var/www/domains/torquebox.org/www/htdocs/
title: TorqueBox
-
intense_debate_base_url: http://torquebox.org
intense_debate_acct: 82f59e335081be13846c34fa627b3208
google_analytics: UA-6435340-2
View
2 _ext/pipeline.rb
@@ -8,6 +8,7 @@
require 'tagger_atomizer'
require 'tag_implier'
require 'json'
+require 'sitemap'
Awestruct::Extensions::Pipeline.new do
@@ -47,4 +48,5 @@
helper RssWidget
extension Documentation.new()
+ extension Sitemap.new( 'sitemap.xml', :pages )
end
View
70 _ext/sitemap.rb
@@ -0,0 +1,70 @@
+
+class Sitemap
+
+ def initialize( output_path, entries_name = :pages )
+ @output_path = output_path
+ @entries_name = entries_name
+ end
+
+ def execute( site )
+ entries = site.send( @entries_name )
+ sitemap_pages = []
+
+ entries.each do |entry|
+ if valid_sitemap_entry( entry )
+ sitemap_entry = site.engine.load_page(entry.source_path, :relative_path => entry.relative_source_path, :html_entities => false)
+ sitemap_entry.output_path = entry.output_path
+ sitemap_entry.date = last_update( entry, sitemap_entry )
+ sitemap_entry.priority = 1
+ sitemap_entry.change_frequency = change_frequency( entry, sitemap_entry )
+ sitemap_pages << sitemap_entry
+ end
+ end
+
+ site.engine.set_urls( sitemap_pages )
+
+ sitemap = File.join( File.dirname(__FILE__), 'sitemap.xml.haml' )
+ page = site.engine.load_page( sitemap )
+ page.date = Time.now
+ page.output_path = @output_path
+ page.sitemap_entries = sitemap_pages
+ page.title = site.title || site.base_url
+ site.pages << page
+ end
+
+ protected
+ def change_frequency( page, sitemap_entry )
+ if page.change_frequency.nil?
+ if sitemap_entry.change_frequency.nil?
+ 'never'
+ else
+ sitemap_entry.change_frequency
+ end
+ else
+ page.change_frequency
+ end
+ end
+
+ def last_update( page, sitemap_entry )
+ if sitemap_entry.timestamp.nil?
+ page.date.nil? ? Time.now : page.date
+ else
+ sitemap_entry.timestamp
+ end
+ end
+
+ def valid_sitemap_entry( page )
+ page.output_filename != '.htaccess' &&
+ page.output_filename != 'screen.css' &&
+ page.output_filename != 'print.css' &&
+ page.output_filename != 'ie.css' &&
+ page.output_filename != 'robots.txt' &&
+ page.output_extension != '.atom' &&
+ page.output_extension != '.scss' &&
+ page.output_extension != '.css' &&
+ page.output_extension != '.png' &&
+ page.output_extension != '.jpg' &&
+ page.output_extension != '.gif' &&
+ page.output_extension != '.js'
+ end
+end
View
13 _ext/sitemap.xml.haml
@@ -0,0 +1,13 @@
+---
+---
+!!! XML
+
+%urlset{ :xmlns=>'http://www.sitemaps.org/schemas/sitemap/0.9' }
+ - unless page.sitemap_entries.empty?
+ - for entry in page.sitemap_entries
+ %url
+ %loc #{site.base_url}#{entry.url}
+ %lastmod= entry.date
+ %priority= entry.priority
+ %changefreq= entry.change_frequency
+
View
1 _layouts/default.html.haml
@@ -1,5 +1,6 @@
---
layout: base
+change_frequency: weekly
---
#nav-wrapper
View
1 _layouts/news.html.haml
@@ -1,5 +1,6 @@
---
layout: default
+change_frequency: monthly
---
#right-sidebar
View
2 robots.txt
@@ -0,0 +1,2 @@
+User-agent: *
+Allow: /

0 comments on commit 9fa91e1

Please sign in to comment.