Class: SimpleSitemapGenerator::Generator
- Inherits:
-
Object
- Object
- SimpleSitemapGenerator::Generator
- Defined in:
- lib/simple_sitemap_generator.rb
Instance Attribute Summary collapse
-
#additional_paths ⇒ Object
Returns the value of attribute additional_paths.
-
#default_changefreq ⇒ Object
Returns the value of attribute default_changefreq.
-
#default_lastmod ⇒ Object
Returns the value of attribute default_lastmod.
-
#default_priority ⇒ Object
Returns the value of attribute default_priority.
-
#host ⇒ Object
Returns the value of attribute host.
-
#inappropriate_paths ⇒ Object
Returns the value of attribute inappropriate_paths.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #generate_xml ⇒ Object
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize ⇒ Generator
Returns a new instance of Generator.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/simple_sitemap_generator.rb', line 19 def initialize @default_changefreq = 'daily' @default_priority = 0.5 @inappropriate_paths = [ /:/, # ignore paths like 'users/:id', 'pages/:page' /sitemap\.xml/, ] @host = '' @options = {} @additional_paths = [] end |
Instance Attribute Details
#additional_paths ⇒ Object
Returns the value of attribute additional_paths.
5 6 7 |
# File 'lib/simple_sitemap_generator.rb', line 5 def additional_paths @additional_paths end |
#default_changefreq ⇒ Object
Returns the value of attribute default_changefreq.
5 6 7 |
# File 'lib/simple_sitemap_generator.rb', line 5 def default_changefreq @default_changefreq end |
#default_lastmod ⇒ Object
Returns the value of attribute default_lastmod.
5 6 7 |
# File 'lib/simple_sitemap_generator.rb', line 5 def default_lastmod @default_lastmod end |
#default_priority ⇒ Object
Returns the value of attribute default_priority.
5 6 7 |
# File 'lib/simple_sitemap_generator.rb', line 5 def default_priority @default_priority end |
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/simple_sitemap_generator.rb', line 5 def host @host end |
#inappropriate_paths ⇒ Object
Returns the value of attribute inappropriate_paths.
5 6 7 |
# File 'lib/simple_sitemap_generator.rb', line 5 def inappropriate_paths @inappropriate_paths end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/simple_sitemap_generator.rb', line 5 def @options end |
Instance Method Details
#generate_xml ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/simple_sitemap_generator.rb', line 7 def generate_xml paths.map { |path| { loc: @host + path, lastmod: @options[path.to_sym]&.[](:lastmod) || @default_lastmod, changefreq: @options[path.to_sym]&.[](:changefreq) || @default_changefreq, priority: @options[path.to_sym]&.[](:priority) || @default_priority, }.compact } .to_xml(root: 'url', skip_types: true) .gsub(default_root_start_tag, root_start_tag) .gsub(default_root_end_tag, root_end_tag) end |