Class: HTMLProofer::Check::OpenGraph

Inherits:
HTMLProofer::Check show all
Defined in:
lib/html_proofer/check/open_graph.rb

Instance Attribute Summary

Attributes inherited from HTMLProofer::Check

#external_urls, #failures, #internal_urls, #options

Instance Method Summary collapse

Methods inherited from HTMLProofer::Check

#add_failure, #add_to_external_urls, #add_to_internal_urls, #create_element, #initialize, #short_name, short_name, subchecks

Methods included from Utils

#blank?, #create_nokogiri, #pluralize

Constructor Details

This class inherits a constructor from HTMLProofer::Check

Instance Method Details

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/html_proofer/check/open_graph.rb', line 6

def run
  @html.css('meta[property="og:url"], meta[property="og:image"]').each do |node|
    @open_graph = create_element(node)

    next if @open_graph.ignore?

    # does the open_graph exist?
    if missing_content?
      add_failure("open graph has no content attribute", element: @open_graph)
    elsif empty_content?
      add_failure("open graph content attribute is empty", element: @open_graph)
    elsif !@open_graph.url.valid?
      add_failure("#{@open_graph.src} is an invalid URL", element: @open_graph)
    elsif @open_graph.url.protocol_relative?
      add_failure(
        "open graph link #{@open_graph.url} is a protocol-relative URL, use explicit https:// instead",
        element: @open_graph,
      )
    elsif @open_graph.url.remote?
      add_to_external_urls(@open_graph.url, @open_graph.line)
    else
      add_failure(
        "internal open graph #{@open_graph.url.raw_attribute} does not exist",
        element: @open_graph,
      ) unless @open_graph.url.exists?
    end
  end

  external_urls
end