Class: Jekyll::SeoTag::JSONLDDrop

Inherits:
Drops::Drop
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/starter_web/_plugins/seo/j1-seo-tags.rb

Instance Method Summary collapse

Constructor Details

#initialize(page_drop) ⇒ JSONLDDrop

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



760
761
762
763
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 760

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

Instance Method Details

#authorObject



771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 771

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

  author_type = page_drop.author["type"]
  return if author_type && !VALID_AUTHOR_TYPES.include?(author_type)

  hash = {
    "@type" => author_type || "Person",
    "name"  => page_drop.author["name"],
  }

  author_url = page_drop.author["url"]
  hash["url"] = author_url if author_url

  hash
end

#fallback_dataObject



765
766
767
768
769
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 765

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

#imageObject



788
789
790
791
792
793
794
795
796
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 788

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



798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 798

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_json(state = nil) ⇒ Object

Returns a JSON-encoded object containing the JSON-LD data. Keys are sorted.



825
826
827
828
829
830
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 825

def to_json(state = nil)
  keys.sort.each_with_object({}) do |(key, _), result|
    v = self[key]
    result[key] = v unless v.nil?
  end.to_json(state)
end