Class: Awestruct::Extensions::Sitemap

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/extensions/sitemap.rb

Instance Method Summary collapse

Instance Method Details

#execute(site) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/awestruct/extensions/sitemap.rb', line 11

def execute( site )

  # 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

  # Add the sitemap to our site
  site.pages << page
end