Class: Aardi::Sitemap
- Inherits:
-
Object
- Object
- Aardi::Sitemap
- Defined in:
- lib/aardi/sitemap.rb
Instance Method Summary collapse
-
#content ⇒ Object
:reek:NestedIterators.
- #record_mtime(path, path_mtime) ⇒ Object
- #render ⇒ Object
- #target_path ⇒ Object
- #update_mtime(path, path_mtime) ⇒ Object
-
#url_details(path, details, urlset) ⇒ Object
Absent a block variable on Nokogiri::XML::Builder.new, this is called by the builder, not sitemap itself, and must be public.
- #urls ⇒ Object
Instance Method Details
#content ⇒ Object
:reek:NestedIterators
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/aardi/sitemap.rb', line 6 def content sitemap = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do urlset(xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9') do |urlset| urls.each do |path, details| url_details(path, details, urlset) end end end sitemap.to_xml end |
#record_mtime(path, path_mtime) ⇒ Object
18 19 20 21 22 |
# File 'lib/aardi/sitemap.rb', line 18 def record_mtime(path, path_mtime) return unless urls.key?(path) && path_mtime update_mtime(path, path_mtime) end |
#render ⇒ Object
24 25 26 27 |
# File 'lib/aardi/sitemap.rb', line 24 def render source = Content.new(content) FileTarget.new(source, target_path).write end |
#target_path ⇒ Object
29 |
# File 'lib/aardi/sitemap.rb', line 29 def target_path = './sitemap.xml' |
#update_mtime(path, path_mtime) ⇒ Object
31 32 33 |
# File 'lib/aardi/sitemap.rb', line 31 def update_mtime(path, path_mtime) urls[path][:lastmod] = path_mtime.iso8601 end |
#url_details(path, details, urlset) ⇒ Object
Absent a block variable on Nokogiri::XML::Builder.new, this is called by the builder, not sitemap itself, and must be public. :reek:FeatureEnvy
38 39 40 41 42 43 44 45 46 |
# File 'lib/aardi/sitemap.rb', line 38 def url_details(path, details, urlset) missing_path(path) unless File.exist?("./#{path}") urlset.url do details.slice(:loc, :lastmod, :changefreq).each do |node, value| urlset.public_send node, value end end end |
#urls ⇒ Object
48 49 50 |
# File 'lib/aardi/sitemap.rb', line 48 def urls @urls ||= Config[:sitemap_entries].to_h { |path, cf| [path, url_values(path, cf)] } end |