lib/nanoc/helpers/xml_sitemap.rb in nanoc-3.4.3 vs lib/nanoc/helpers/xml_sitemap.rb in nanoc-3.5.0b1

- old
+ new

@@ -33,16 +33,20 @@ # # <%= xml_sitemap :items => @items.reject{ |i| i[:is_hidden] || i.binary? } %> # # @option params [Array] :items A list of items to include in the sitemap # + # @option params [Proc] :rep_select A proc to filter reps through. If the + # proc returns true, the rep will be included; otherwise, it will not. + # # @return [String] The XML sitemap def xml_sitemap(params={}) require 'builder' # Extract parameters - items = params.fetch(:items) { @items.reject { |i| i[:is_hidden] } } + items = params.fetch(:items) { @items.reject { |i| i[:is_hidden] } } + select_proc = params.fetch(:rep_select, nil) # Create builder buffer = '' xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2) @@ -53,11 +57,13 @@ # Build sitemap xml.instruct! xml.urlset(:xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9') do # Add item - items.each do |item| - item.reps.reject { |r| r.raw_path.nil? }.each do |rep| + items.sort_by { |i| i.identifier }.each do |item| + reps = item.reps.reject { |r| r.raw_path.nil? } + reps.reject! { |r| !select_proc[r] } if select_proc + reps.sort_by { |r| r.name.to_s }.each do |rep| xml.url do xml.loc @site.config[:base_url] + rep.path xml.lastmod item[:mtime].to_iso8601_date unless item[:mtime].nil? xml.changefreq item[:changefreq] unless item[:changefreq].nil? xml.priority item[:priority] unless item[:priority].nil?