Class: SimpleSitemap::Generators::Index
- Defined in:
- lib/simple_sitemap/generators/index.rb
Instance Attribute Summary collapse
-
#sitemaps ⇒ Object
Returns the value of attribute sitemaps.
Attributes inherited from Base
Instance Method Summary collapse
- #add_sitemap(name) ⇒ Object
-
#initialize(config, hooks) ⇒ Index
constructor
A new instance of Index.
- #to_xml ⇒ Object
- #write! ⇒ Object
Constructor Details
#initialize(config, hooks) ⇒ Index
Returns a new instance of Index.
12 13 14 15 |
# File 'lib/simple_sitemap/generators/index.rb', line 12 def initialize(config, hooks) super @sitemaps = [] end |
Instance Attribute Details
#sitemaps ⇒ Object
Returns the value of attribute sitemaps.
10 11 12 |
# File 'lib/simple_sitemap/generators/index.rb', line 10 def sitemaps @sitemaps end |
Instance Method Details
#add_sitemap(name) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/simple_sitemap/generators/index.rb', line 17 def add_sitemap(name) url = if @config.sitemap_location[-1,1] == '/' "#{@config.sitemap_location}#{name}" else "#{@config.sitemap_location}/#{name}" end @sitemaps << url end |
#to_xml ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/simple_sitemap/generators/index.rb', line 38 def to_xml builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.sitemapindex(xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9') do @sitemaps.each do |sitemap_url| xml.sitemap do xml.loc sitemap_url end end end end builder.to_xml end |
#write! ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/simple_sitemap/generators/index.rb', line 26 def write! xml = to_xml index_filename = 'index.xml' if @config.prefix index_filename = "#{@config.prefix}_#{index_filename}" end if @config.gzip index_filename << '.gz' end write_file index_filename, xml end |