Module: Spotlight::MetaHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/spotlight/meta_helper.rb

Overview

HTML <meta> tag helpers

Instance Method Summary collapse

Instance Method Details

#add_browse_meta_content(browse) ⇒ Object



76
77
78
79
# File 'app/helpers/spotlight/meta_helper.rb', line 76

def add_browse_meta_content(browse)
  browse_twitter_card_content(browse)
  browse_opengraph_content(browse)
end

#add_document_meta_content(document) ⇒ Object



100
101
102
103
# File 'app/helpers/spotlight/meta_helper.rb', line 100

def add_document_meta_content(document)
  document_twitter_card_content(document)
  document_opengraph_content(document)
end

#add_exhibit_meta_contentObject

rubocop:enable Rails/OutputSafety



25
26
27
28
# File 'app/helpers/spotlight/meta_helper.rb', line 25

def add_exhibit_meta_content
  exhibit_twitter_card_content
  exhibit_opengraph_content
end

#add_page_meta_content(page) ⇒ Object



52
53
54
55
# File 'app/helpers/spotlight/meta_helper.rb', line 52

def add_page_meta_content(page)
  page_twitter_card_content(page)
  page_opengraph_content(page)
end

#browse_opengraph_content(browse) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'app/helpers/spotlight/meta_helper.rb', line 89

def browse_opengraph_content(browse)
  card('og') do |graph|
    graph['type'] = 'article'
    graph['site_name'] = application_name
    graph['title'] = browse.title
    graph['image'] = browse.thumbnail.iiif_url if browse.thumbnail
    graph['article:published_time'] = browse.created_at.iso8601
    graph['article:modified_time'] = browse.updated_at.iso8601
  end
end

#browse_twitter_card_content(browse) ⇒ Object



81
82
83
84
85
86
87
# File 'app/helpers/spotlight/meta_helper.rb', line 81

def browse_twitter_card_content(browse)
  card('twitter') do |card|
    card['card'] = 'summary_large_image'
    card['title'] = browse.title
    card['image'] = browse.thumbnail.iiif_url if browse.thumbnail
  end
end

#build_tags(attributes, tag_field) ⇒ Object

rubocop:disable Rails/OutputSafety



17
18
19
20
21
22
# File 'app/helpers/spotlight/meta_helper.rb', line 17

def build_tags(attributes, tag_field)
  type_fields = { 'og' => 'property', 'twitter' => 'name' }
  attributes.map do |key, value|
    ActionController::Base.helpers.tag.meta("#{type_fields[tag_field]}": "#{tag_field}:#{key}", content: value) if value
  end.compact.join("\n").html_safe
end

#card(type, &block) ⇒ Object



10
11
12
13
14
# File 'app/helpers/spotlight/meta_helper.rb', line 10

def card(type, &block)
  card = {}
  block.call(card) if block_given?
  content_for(:meta) { build_tags(card, type) }
end

#description(description) ⇒ Object



6
7
8
# File 'app/helpers/spotlight/meta_helper.rb', line 6

def description(description)
  content_for(:meta) { ActionController::Base.helpers.tag.meta(name: 'description', content: description) } if description
end

#document_opengraph_content(document) ⇒ Object



115
116
117
118
119
120
121
122
123
# File 'app/helpers/spotlight/meta_helper.rb', line 115

def document_opengraph_content(document)
  presenter = document_presenter(document)

  card('og') do |graph|
    graph['site_name'] = application_name
    graph['title'] = presenter.heading
    graph['image'] = document.first(blacklight_config.index.thumbnail_field)
  end
end

#document_twitter_card_content(document) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'app/helpers/spotlight/meta_helper.rb', line 105

def document_twitter_card_content(document)
  presenter = document_presenter(document)

  card('twitter') do |card|
    card['card'] = 'summary_large_image'
    card['title'] = presenter.heading
    card['image'] = document.first(blacklight_config.index.thumbnail_field)
  end
end

#exhibit_opengraph_contentObject



44
45
46
47
48
49
50
# File 'app/helpers/spotlight/meta_helper.rb', line 44

def exhibit_opengraph_content
  card('og') do |graph|
    graph['title'] = current_exhibit.title
    graph['image'] = meta_image if current_exhibit.thumbnail
    graph['site_name'] = site_title
  end
end

#exhibit_twitter_card_contentObject



30
31
32
33
34
35
36
37
38
# File 'app/helpers/spotlight/meta_helper.rb', line 30

def exhibit_twitter_card_content
  card('twitter') do |card|
    card['card'] = 'summary'
    card['url'] = spotlight.exhibit_root_url(current_exhibit)
    card['title'] = current_exhibit.title
    card['description'] = current_exhibit.subtitle
    card['image'] = meta_image if current_exhibit.thumbnail
  end
end

#meta_imageObject



40
41
42
# File 'app/helpers/spotlight/meta_helper.rb', line 40

def meta_image
  current_exhibit.thumbnail.iiif_url
end

#page_opengraph_content(page) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/spotlight/meta_helper.rb', line 65

def page_opengraph_content(page)
  card('og') do |graph|
    graph['type'] = 'article'
    graph['site_name'] = application_name
    graph['title'] = page.title
    graph['image'] = page.thumbnail.iiif_url if page.thumbnail
    graph['article:published_time'] = page.created_at.iso8601
    graph['article:modified_time'] = page.updated_at.iso8601
  end
end

#page_twitter_card_content(page) ⇒ Object



57
58
59
60
61
62
63
# File 'app/helpers/spotlight/meta_helper.rb', line 57

def page_twitter_card_content(page)
  card('twitter') do |card|
    card['card'] = 'summary_large_image'
    card['title'] = page.title
    card['image'] = page.thumbnail.iiif_url if page.thumbnail
  end
end