2017-10-22 16:37:44 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-23 20:11:55 +00:00
|
|
|
module Jekyll
|
|
|
|
class SeoTag
|
|
|
|
class JSONLDDrop < Jekyll::Drops::Drop
|
|
|
|
extend Forwardable
|
|
|
|
|
|
|
|
def_delegator :page_drop, :name, :name
|
|
|
|
def_delegator :page_drop, :description, :description
|
|
|
|
def_delegator :page_drop, :canonical_url, :url
|
|
|
|
def_delegator :page_drop, :page_title, :headline
|
|
|
|
def_delegator :page_drop, :date_modified, :dateModified
|
|
|
|
def_delegator :page_drop, :date_published, :datePublished
|
|
|
|
def_delegator :page_drop, :links, :sameAs
|
|
|
|
def_delegator :page_drop, :logo, :logo
|
2017-08-24 17:05:56 +00:00
|
|
|
def_delegator :page_drop, :type, :type
|
2017-08-23 20:11:55 +00:00
|
|
|
|
2017-08-24 17:05:28 +00:00
|
|
|
# Expose #type and #logo as private methods and #@type as a public method
|
2017-08-23 20:11:55 +00:00
|
|
|
alias_method :"@type", :type
|
|
|
|
private :type
|
|
|
|
private :logo
|
|
|
|
|
|
|
|
# page_drop should be an instance of Jekyll::SeoTag::Drop
|
|
|
|
def initialize(page_drop)
|
|
|
|
@mutations = {}
|
|
|
|
@page_drop = page_drop
|
|
|
|
end
|
|
|
|
|
|
|
|
def fallback_data
|
|
|
|
{
|
|
|
|
"@context" => "http://schema.org",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def author
|
|
|
|
return unless page_drop.author["name"]
|
|
|
|
{
|
|
|
|
"@type" => "Person",
|
|
|
|
"name" => page_drop.author["name"],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def publisher
|
|
|
|
return unless logo
|
|
|
|
output = {
|
|
|
|
"@type" => "Organization",
|
|
|
|
"logo" => {
|
|
|
|
"@type" => "ImageObject",
|
|
|
|
"url" => logo,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
output["name"] = page_drop.author.name if page_drop.author.name
|
|
|
|
output
|
|
|
|
end
|
|
|
|
|
|
|
|
def main_entity
|
|
|
|
return unless %w(BlogPosting CreativeWork).include?(type)
|
|
|
|
{
|
|
|
|
"@type" => "WebPage",
|
|
|
|
"@id" => page_drop.canonical_url,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
alias_method :mainEntityOfPage, :main_entity
|
|
|
|
private :main_entity
|
|
|
|
|
2017-11-16 16:40:42 +00:00
|
|
|
def to_json
|
|
|
|
to_h.reject { |_k, v| v.nil? }.to_json
|
|
|
|
end
|
|
|
|
|
2017-08-23 20:11:55 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :page_drop
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|