Class: Blacklight::OpenGraphMetadataComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/open_graph_metadata_component.rb

Overview

Renders tags in the with Open Graph metadata

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(presenter: nil) ⇒ OpenGraphMetadataComponent

Returns a new instance of OpenGraphMetadataComponent.

Parameters:

  • presenter (#properties, nil) (defaults to: nil) —

    page-specific Open Graph properties



9
10
11
# File 'app/components/blacklight/open_graph_metadata_component.rb', line 9

def initialize(presenter: nil)
  @presenter = presenter
end

Instance Attribute Details

#presenter ⇒ Object (readonly)

Returns the value of attribute presenter.



6
7
8
# File 'app/components/blacklight/open_graph_metadata_component.rb', line 6

def presenter
  @presenter
end

Instance Method Details

#call ⇒ Object

Render all entries in properties as tags



29
30
31
# File 'app/components/blacklight/open_graph_metadata_component.rb', line 29

def call
  safe_join(properties.map { |property, content| tag.meta(property:, content: helpers.strip_tags(content)) }, "\n")
end

#default_properties ⇒ Object

Base set of properties that will be rendered on every page



19
20
21
22
23
24
25
26
# File 'app/components/blacklight/open_graph_metadata_component.rb', line 19

def default_properties
  {
    'og:type' => 'website',
    'og:site_name' => helpers.application_name,
    'og:title' => helpers.render_page_title,
    'og:url' => request.original_url
  }
end

#properties ⇒ Object

Hash of property:content pairs that will become tags



14
15
16
# File 'app/components/blacklight/open_graph_metadata_component.rb', line 14

def properties
  default_properties.merge((presenter&.properties || {}).transform_keys(&:to_s)).compact_blank
end