lib/awestruct/extensions/sitemap.rb in awestruct-0.4.5 vs lib/awestruct/extensions/sitemap.rb in awestruct-0.4.6

- old
+ new

@@ -6,12 +6,27 @@ module Awestruct module Extensions class Sitemap + def initialize + @excluded_files = [ '/.htaccess', '/favicon.ico' ,'/robots.txt', ].to_set + @excluded_extensions = ['.atom', '.scss', '.css', '.png', '.jpg', '.gif', '.js' ].to_set + end + def execute( site ) + # Add additional excludes from _config/sitemap.yml + if site.sitemap + if site.sitemap["excluded_files"] + @excluded_files.merge(site.sitemap.excluded_files) + end + if site.sitemap["excluded_extensions"] + @excluded_extensions.merge(site.sitemap.excluded_extensions) + end + end + # Go through all of the site's pages and add sitemap metadata sitemap_pages = [] entries = site.pages entries.each { |entry| sitemap_pages << set_sitemap_data( entry ) if valid_sitemap_entry( entry ) } if entries @@ -65,21 +80,10 @@ page.lastmod = Time.now.strftime( "%Y-%m-%d" ) 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' + !@excluded_files.member?(page.output_path) && !@excluded_extensions.member?(page.output_extension) end end end end