Sha256: 7e6baf2161be980f0d2cf35f899348a4e111bd22eb3751c8fa3393a2af46a18d

Contents?: true

Size: 829 Bytes

Versions: 20

Compression:

Stored size: 829 Bytes

Contents

module Spotlight
  module Resources
    ##
    # OpenGraph metadata harvester
    module OpenGraph
      extend ActiveSupport::Concern
      include Spotlight::Resources::Web

      def opengraph
        @opengraph ||= begin
          page = {}

          body.css('meta').select { |m| m.attribute('property') }.each do |m|
            page[m.attribute('property').to_s] = m.attribute('content').to_s
          end

          page
        end
      end

      def opengraph_properties
        Hash[opengraph.map do |k, v|
          ["#{opengraph_solr_field_name(k)}_tesim", v]
        end]
      end

      private

      def opengraph_solr_field_name(field)
        if Rails::VERSION::MAJOR >= 5
          field.parameterize(separator: '_')
        else
          field.parameterize('_')
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
blacklight-spotlight-0.34.1 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.34.0 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.33.3 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.33.2 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.33.1 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.33.0 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.32.0 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.31.0 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.30.0 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.29.1 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.29.0 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.28.3 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.28.2 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.28.1 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.28.0 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.27.0 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.26.1 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.26.0 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.25.0 app/models/concerns/spotlight/resources/open_graph.rb
blacklight-spotlight-0.24.0 app/models/concerns/spotlight/resources/open_graph.rb