Class: Wytch::SitemapView
- Inherits:
-
Object
- Object
- Wytch::SitemapView
- Defined in:
- lib/wytch/sitemap_view.rb
Overview
Generates an XML sitemap for the site.
This view renders a sitemap.xml file listing all pages that have
include_in_sitemap? returning true.
Instance Method Summary collapse
-
#call ⇒ String
Renders the sitemap XML.
-
#initialize(page) ⇒ SitemapView
constructor
Creates a new sitemap view.
Constructor Details
#initialize(page) ⇒ SitemapView
Creates a new sitemap view.
16 17 18 |
# File 'lib/wytch/sitemap_view.rb', line 16 def initialize(page) @page = page end |
Instance Method Details
#call ⇒ String
Renders the sitemap XML.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wytch/sitemap_view.rb', line 23 def call require "builder" xml = ::Builder::XmlMarkup.new(indent: 2) xml.instruct! :xml, version: "1.0", encoding: "UTF-8" xml.urlset xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" do Wytch.site.pages.values.each do |page| next unless page.include_in_sitemap? xml.url do xml.loc "#{Wytch.site.base_url}#{page.path}" xml.lastmod page.last_modified if page.last_modified xml.changefreq page.change_frequency if page.change_frequency xml.priority page.priority if page.priority end end end end |