Class: OpenGraphCheck

Inherits:
HTMLProofer::Check show all
Defined in:
lib/html-proofer/check/opengraph.rb

Instance Attribute Summary

Attributes inherited from HTMLProofer::Check

#element, #external_urls, #html, #internal_urls, #issues, #node, #options, #path, #src

Instance Method Summary collapse

Methods inherited from HTMLProofer::Check

#add_issue, #add_to_external_urls, #add_to_internal_urls, #blank?, #create_element, #initialize, subchecks

Constructor Details

This class inherits a constructor from HTMLProofer::Check

Instance Method Details

#empty_src?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/html-proofer/check/opengraph.rb', line 20

def empty_src?
  blank?(@opengraph.src)
end

#missing_src?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/html-proofer/check/opengraph.rb', line 16

def missing_src?
  !@opengraph.src
end

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/html-proofer/check/opengraph.rb', line 24

def run
  @html.css('meta[property="og:url"], meta[property="og:image"]').each do |m|
    @opengraph = OpenGraphElement.new(m, self, @logger)

    next if @opengraph.ignore?

    # does the opengraph exist?
    if missing_src?
      add_issue('open graph has no content attribute', line: m.line, content: m.content)
    elsif empty_src?
      add_issue('open graph content attribute is empty', line: m.line, content: m.content)
    elsif !@opengraph.valid?
      add_issue("#{@opengraph.src} is an invalid URL", line: m.line)
    elsif @opengraph.remote?
      add_to_external_urls(@opengraph.url)
    else
      add_issue("internal open graph #{@opengraph.url} does not exist", line: m.line, content: m.content) unless @opengraph.exists?
    end
  end

  external_urls
end