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:



32
33
34
35
# File 'app/models/concerns/spotlight/sitemap.rb', line 32

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

Instance Attribute Details

#exhibitObject (readonly)

Returns the value of attribute exhibit.



4
5
6
# File 'app/models/concerns/spotlight/sitemap.rb', line 4

def exhibit
  @exhibit
end

#sitemapObject (readonly)

Returns the value of attribute sitemap.



4
5
6
# File 'app/models/concerns/spotlight/sitemap.rb', line 4

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



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

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:



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

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



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

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



50
51
52
# File 'app/models/concerns/spotlight/sitemap.rb', line 50

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

#add_pagesObject

Add all published feature and about pages to the sitemap



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

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



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

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



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

def add_resources!
  return unless exhibit.published?

  add_exhibit_root
  add_pages
  add_resources
  add_browse_categories
end