Drop#image should return nil if there is no image#path in order to avoid a breaking change
This commit is contained in:
parent
1081a0ebd9
commit
298d3b03d6
|
@ -130,8 +130,11 @@ module Jekyll
|
|||
end
|
||||
end
|
||||
|
||||
# Returns a Drop representing the page's image
|
||||
# Returns nil if the image has no path, to preserve backwards compatability
|
||||
def image
|
||||
@image ||= ImageDrop.new(:page => page, :context => @context)
|
||||
@image if @image.path
|
||||
end
|
||||
|
||||
def page_lang
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
module Jekyll
|
||||
class SeoTag
|
||||
# Returns nil or a hash representing the page image
|
||||
# The image hash will always contain a path, pulled from:
|
||||
# A drop representing the page image
|
||||
# The image path will be pulled from:
|
||||
#
|
||||
# 1. The `image` key if it's a string
|
||||
# 2. The `image.path` key if it's a hash
|
||||
# 3. The `image.facebook` key
|
||||
# 4. The `image.twitter` key
|
||||
#
|
||||
# The resulting path is always an absolute URL
|
||||
class ImageDrop < Jekyll::Drops::Drop
|
||||
include Jekyll::SeoTag::UrlHelper
|
||||
|
||||
# Initialize a new ImageDrop
|
||||
#
|
||||
# page - The page hash (e.g., Page#to_liquid)
|
||||
# context - the Liquid::Context
|
||||
def initialize(page: nil, context: nil)
|
||||
raise ArgumentError unless page && context
|
||||
@mutations = {}
|
||||
|
@ -22,6 +21,9 @@ module Jekyll
|
|||
@context = context
|
||||
end
|
||||
|
||||
# Called path for backwards compatability, this is really
|
||||
# the escaped, absolute URL representing the page's image
|
||||
# Returns nil if no image path can be determined
|
||||
def path
|
||||
@path ||= filters.uri_escape(absolute_url) if absolute_url
|
||||
end
|
||||
|
@ -32,9 +34,10 @@ module Jekyll
|
|||
attr_accessor :page
|
||||
attr_accessor :context
|
||||
|
||||
# The normalized image hash with a `path` key (which may be nil)
|
||||
def image_hash
|
||||
@image_hash ||= if page["image"].is_a?(Hash)
|
||||
page["image"]
|
||||
{ "path" => nil }.merge(page["image"])
|
||||
elsif page["image"].is_a?(String)
|
||||
{ "path" => page["image"] }
|
||||
else
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
module Jekyll
|
||||
class SeoTag
|
||||
# Mixin to share common URL-related methods between class
|
||||
module UrlHelper
|
||||
private
|
||||
|
||||
# Determines if the given string is an absolute URL
|
||||
#
|
||||
# Returns true if an absolute URL.
|
||||
# Retruns false if it's a relative URL
|
||||
# Returns nil if it is not a string or can't be parsed as a URL
|
||||
def absolute_url?(string)
|
||||
return unless string
|
||||
Addressable::URI.parse(string).absolute?
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<meta property="og:site_name" content="{{ seo_tag.site_title }}" />
|
||||
{% endif %}
|
||||
|
||||
{% if seo_tag.image.path %}
|
||||
{% if seo_tag.image %}
|
||||
<meta property="og:image" content="{{ seo_tag.image.path }}" />
|
||||
{% if seo_tag.image.height %}
|
||||
<meta property="og:image:height" content="{{ seo_tag.image.height }}" />
|
||||
|
@ -50,7 +50,7 @@
|
|||
{% endif %}
|
||||
|
||||
{% if site.twitter %}
|
||||
{% if seo_tag.image.path %}
|
||||
{% if seo_tag.image %}
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
{% else %}
|
||||
<meta name="twitter:card" content="summary" />
|
||||
|
|
Loading…
Reference in New Issue