Class: Jekyll::SeoTag::JSONLDDrop

Inherits:
Drops::Drop
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jekyll-seo-tag/json_ld_drop.rb

Instance Method Summary collapse

Constructor Details

#initialize(page_drop) ⇒ JSONLDDrop

page_drop should be an instance of Jekyll::SeoTag::Drop


27
28
29
30
# File 'lib/jekyll-seo-tag/json_ld_drop.rb', line 27

def initialize(page_drop)
  @mutations = {}
  @page_drop = page_drop
end

Instance Method Details

#authorObject


38
39
40
41
42
43
44
45
# File 'lib/jekyll-seo-tag/json_ld_drop.rb', line 38

def author
  return unless page_drop.author["name"]

  {
    "@type" => "Person",
    "name"  => page_drop.author["name"],
  }
end

#fallback_dataObject


32
33
34
35
36
# File 'lib/jekyll-seo-tag/json_ld_drop.rb', line 32

def fallback_data
  @fallback_data ||= {
    "@context" => "https://schema.org",
  }
end

#imageObject


47
48
49
50
51
52
53
54
55
# File 'lib/jekyll-seo-tag/json_ld_drop.rb', line 47

def image
  return unless page_drop.image
  return page_drop.image.path if page_drop.image.keys.length == 1

  hash = page_drop.image.to_h
  hash["url"]   = hash.delete("path")
  hash["@type"] = "imageObject"
  hash
end

#publisherObject


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/jekyll-seo-tag/json_ld_drop.rb', line 57

def publisher
  return unless 

  output = {
    "@type" => "Organization",
    "logo"  => {
      "@type" => "ImageObject",
      "url"   => ,
    },
  }
  output["name"] = page_drop.author.name if page_drop.author.name
  output
end

#to_jsonObject


82
83
84
# File 'lib/jekyll-seo-tag/json_ld_drop.rb', line 82

def to_json
  to_h.reject { |_k, v| v.nil? }.to_json
end