Class: Spotlight::Sitemap

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/spotlight/sitemap.rb

Overview

Generate a sitemap for the Spotlight exhibit content

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sitemap, exhibit) ⇒ Sitemap

Returns a new instance of Sitemap.

Parameters:



34
35
36
37
# File 'app/models/concerns/spotlight/sitemap.rb', line 34

def initialize(sitemap, exhibit)
  @sitemap = sitemap
  @exhibit = exhibit
end

Instance Attribute Details

#exhibitObject (readonly)

Returns the value of attribute exhibit.



6
7
8
# File 'app/models/concerns/spotlight/sitemap.rb', line 6

def exhibit
  @exhibit
end

#sitemapObject (readonly)

Returns the value of attribute sitemap.



6
7
8
# File 'app/models/concerns/spotlight/sitemap.rb', line 6

def sitemap
  @sitemap
end

Class Method Details

.add_all_exhibits(sitemap) ⇒ Object

Add all (published) spotlight exhibits to the given sitemap

Parameters:

  • Sitemap (Sitemap::Interpreter)

    instance provided by sitemap_generator



12
13
14
15
16
17
18
# File 'app/models/concerns/spotlight/sitemap.rb', line 12

def self.add_all_exhibits(sitemap)
  SitemapGenerator::Interpreter.send :include, Spotlight::Engine.routes.url_helpers

  Spotlight::Exhibit.published.find_each do |e|
    add_exhibit(sitemap, e)
  end
end

.add_exhibit(sitemap, exhibit) ⇒ Object

Add a single exhibit to the given sitemap

Parameters:



25
26
27
28
29
# File 'app/models/concerns/spotlight/sitemap.rb', line 25

def self.add_exhibit(sitemap, exhibit)
  sitemap = Spotlight::Sitemap.new(sitemap, exhibit)
  sitemap.add_resources!
  sitemap
end

Instance Method Details

#add_browse_categoriesObject

Add published browse categories to the sitemap



70
71
72
73
74
# File 'app/models/concerns/spotlight/sitemap.rb', line 70

def add_browse_categories
  exhibit.searches.published.find_each do |s|
    sitemap.add sitemap.exhibit_browse_path(exhibit, s), priority: 0.5, lastmod: s.updated_at
  end
end

#add_exhibit_rootObject

Add the exhibit home page to the sitemap



52
53
54
# File 'app/models/concerns/spotlight/sitemap.rb', line 52

def add_exhibit_root
  sitemap.add sitemap.exhibit_root_path(exhibit)
end

#add_pagesObject

Add all published feature and about pages to the sitemap



58
59
60
61
62
63
64
65
66
# File 'app/models/concerns/spotlight/sitemap.rb', line 58

def add_pages
  exhibit.feature_pages.published.find_each do |p|
    sitemap.add sitemap.exhibit_feature_page_path(exhibit, p), priority: 0.8, lastmod: p.updated_at
  end

  exhibit.about_pages.published.find_each do |p|
    sitemap.add sitemap.exhibit_about_page_path(exhibit, p), priority: 0.5, lastmod: p.updated_at
  end
end

#add_resourcesObject

Add all catalog resources to the sitemap



78
79
80
81
82
# File 'app/models/concerns/spotlight/sitemap.rb', line 78

def add_resources
  exhibit.solr_documents.each do |d|
    sitemap.add sitemap.exhibit_solr_document_path(exhibit, d), priority: 0.25, lastmod: document_last_modified(d)
  end
end

#add_resources!Object

Add all exhibit resources to the sitemap



41
42
43
44
45
46
47
48
# File 'app/models/concerns/spotlight/sitemap.rb', line 41

def add_resources!
  return unless exhibit.published?

  add_exhibit_root
  add_pages
  add_resources
  add_browse_categories
end