lib/nanoc3/helpers/xml_sitemap.rb in nanoc3-3.2.0a3 vs lib/nanoc3/helpers/xml_sitemap.rb in nanoc3-3.2.0a4
- old
+ new
@@ -27,14 +27,23 @@
#
# * `base_url` — The URL to the site, without trailing slash. For example,
# if the site is at "http://example.com/", the `base_url` would be
# "http://example.com".
#
+ # @example Excluding binary items from the sitemap
+ #
+ # <%= xml_sitemap :items => @items.reject{ |i| i[:is_hidden] || i[:binary] } %>
+ #
+ # @option params [Array] :items A list of items to include in the sitemap
+ #
# @return [String] The XML sitemap
- def xml_sitemap
+ def xml_sitemap(params={})
require 'builder'
+ # Extract parameters
+ items = params[:items] || @items.reject { |i| i[:is_hidden] }
+
# Create builder
buffer = ''
xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2)
# Check for required attributes
@@ -44,10 +53,10 @@
# Build sitemap
xml.instruct!
xml.urlset(:xmlns => 'http://www.google.com/schemas/sitemap/0.84') do
# Add item
- @items.reject { |i| i[:is_hidden] }.each do |item|
+ items.each do |item|
item.reps.reject { |r| r.raw_path.nil? }.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?