module Bunto::SeoTag::JSONLD

Constants

METHODS_KEYS

A hash of instance methods => key in resulting JSON-LD hash

Public Instance Methods

json_ld() click to toggle source
# File lib/bunto-seo-tag/json_ld.rb, line 22
def json_ld
  @json_ld ||= begin
    output = {}
    METHODS_KEYS.each do |method, key|
      value = send(method)
      output[key] = value unless value.nil?
    end
    output
  end
end

Private Instance Methods

json_author() click to toggle source
# File lib/bunto-seo-tag/json_ld.rb, line 39
def json_author
  return unless author
  {
    "@type" => "Person",
    "name"  => author["name"],
  }
end
json_context() click to toggle source
# File lib/bunto-seo-tag/json_ld.rb, line 35
def json_context
  "http://schema.org"
end
json_image() click to toggle source
# File lib/bunto-seo-tag/json_ld.rb, line 47
def json_image
  return unless image
  return image["path"] if image.length == 1

  hash = image.dup
  hash["url"]   = hash.delete("path")
  hash["@type"] = "imageObject"
  hash
end
main_entity() click to toggle source
# File lib/bunto-seo-tag/json_ld.rb, line 70
def main_entity
  return unless %w(BlogPosting CreativeWork).include?(type)
  {
    "@type" => "WebPage",
    "@id"   => canonical_url,
  }
end
publisher() click to toggle source
# File lib/bunto-seo-tag/json_ld.rb, line 57
def publisher
  return unless logo
  output = {
    "@type" => "Organization",
    "logo"  => {
      "@type" => "ImageObject",
      "url"   => logo,
    },
  }
  output["name"] = author["name"] if author
  output
end