Class: Awestruct::Extensions::Sitemap
- Inherits:
-
Object
- Object
- Awestruct::Extensions::Sitemap
- Defined in:
- lib/awestruct/extensions/sitemap.rb
Instance Method Summary collapse
- #execute(site) ⇒ Object
-
#initialize ⇒ Sitemap
constructor
A new instance of Sitemap.
Constructor Details
#initialize ⇒ Sitemap
Returns a new instance of Sitemap.
12 13 14 15 |
# File 'lib/awestruct/extensions/sitemap.rb', line 12 def initialize @excluded_files = [ '/.htaccess', '/favicon.ico' ,'/robots.txt', ].to_set @excluded_extensions = ['.atom', '.scss', '.css', '.less', '.png', '.jpg', '.gif', '.js', '.ico', '.svg', '' ].to_set end |
Instance Method Details
#execute(site) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/awestruct/extensions/sitemap.rb', line 17 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 # Check for a specified stylesheet for the sitemap if site.sitemap["stylesheet_url"] stylesheet_url = site.sitemap["stylesheet_url"] 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 # Generate sitemap pages for stuff in _config/sitemap.yml site.sitemap.pages.each do |entry| page = Awestruct::Page.new( site ) page.output_path = entry.url page.date = entry.date( nil ) page.priority = entry.priority( nil ) page.change_frequency = entry.change_frequency( nil ) sitemap_pages << page end if site.sitemap # Generate the correct urls for each page in the sitemap site.engine.set_urls( sitemap_pages ) # Create a sitemap.xml file from our template sitemap = File.join( File.dirname(__FILE__), 'sitemap.xml.haml' ) page = site.engine.load_page( sitemap ) page.output_path = 'sitemap.xml' page.sitemap_entries = sitemap_pages page.do_not_track_dependencies = true page.stylesheet_url = stylesheet_url || nil # Add the sitemap to our site site.pages << page end |