Class: Aardi::Sitemap

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

Instance Method Summary collapse

Instance Method Details

#contentObject

: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

#renderObject



18
19
20
21
# File 'lib/aardi/sitemap.rb', line 18

def render
  source = Content.new(content)
  FileTarget.new(source, target_path).write
end

#target_pathObject



23
# File 'lib/aardi/sitemap.rb', line 23

def target_path = './sitemap.xml'

#update_mtime(path, path_mtime) ⇒ Object



25
26
27
# File 'lib/aardi/sitemap.rb', line 25

def update_mtime(path, path_mtime)
  urls[path][:lastmod] = path_mtime.iso8601
end

#url_details(path, details, urlset) ⇒ Object

Methods called inside builder blocks must be public. :reek:FeatureEnvy



31
32
33
34
35
36
37
38
39
# File 'lib/aardi/sitemap.rb', line 31

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

#urlsObject



41
42
43
# File 'lib/aardi/sitemap.rb', line 41

def urls
  @urls ||= Aardi.config[:sitemap_entries].to_h { |path, cf| [path, url_values(path, cf)] }
end