diff --git a/jekyll-seo-tag.gemspec b/jekyll-seo-tag.gemspec index d368dc2..23084f4 100644 --- a/jekyll-seo-tag.gemspec +++ b/jekyll-seo-tag.gemspec @@ -32,5 +32,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.15" spec.add_development_dependency "html-proofer", "~> 3.7" spec.add_development_dependency "rspec", "~> 3.5" - spec.add_development_dependency "rubocop-jekyll", "~> 0.1.0" + spec.add_development_dependency "rubocop-jekyll", "~> 0.3" end diff --git a/lib/jekyll-seo-tag.rb b/lib/jekyll-seo-tag.rb index e0b7ec9..933fc53 100644 --- a/lib/jekyll-seo-tag.rb +++ b/lib/jekyll-seo-tag.rb @@ -24,7 +24,7 @@ module Jekyll # We will not strip any whitespace if the next character is a '-' # so that we do not interfere with the HTML comment at the # very begining - MINIFY_REGEX = %r!(?<=[{}]|[>,]\n)\s+(?\!-)! + MINIFY_REGEX = %r!(?<=[{}]|[>,]\n)\s+(?\!-)!.freeze def initialize(_tag_name, text, _tokens) super diff --git a/lib/jekyll-seo-tag/author_drop.rb b/lib/jekyll-seo-tag/author_drop.rb index 94a6b68..a23c850 100644 --- a/lib/jekyll-seo-tag/author_drop.rb +++ b/lib/jekyll-seo-tag/author_drop.rb @@ -19,6 +19,7 @@ module Jekyll # site - The Jekyll::Drops::SiteDrop def initialize(page: nil, site: nil) raise ArgumentError unless page && site + @mutations = {} @page = page @site = site @@ -33,6 +34,7 @@ module Jekyll def twitter return @twitter if defined? @twitter + twitter = author_hash["twitter"] || author_hash["name"] @twitter = twitter.is_a?(String) ? twitter.sub(%r!^@!, "") : nil end @@ -47,6 +49,7 @@ module Jekyll # Returns a string or hash representing the author def resolved_author return @resolved_author if defined? @resolved_author + sources = [page["author"]] sources << page["authors"].first if page["authors"].is_a?(Array) sources << site["author"] @@ -61,6 +64,7 @@ module Jekyll @site_data_hash ||= begin return {} unless resolved_author.is_a?(String) return {} unless site.data["authors"].is_a?(Hash) + author_hash = site.data["authors"][resolved_author] author_hash.is_a?(Hash) ? author_hash : {} end diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index e8887bd..354c07f 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -9,7 +9,7 @@ module Jekyll FORMAT_STRING_METHODS = [ :markdownify, :strip_html, :normalize_whitespace, :escape_once, ].freeze - HOMEPAGE_OR_ABOUT_REGEX = %r!^/(about/)?(index.html?)?$! + HOMEPAGE_OR_ABOUT_REGEX = %r!^/(about/)?(index.html?)?$!.freeze def initialize(text, context) @obj = {} @@ -26,6 +26,7 @@ module Jekyll def title? return false unless title return @display_title if defined?(@display_title) + @display_title = (@text !~ %r!title=false!i) end @@ -63,6 +64,7 @@ module Jekyll def name return @name if defined?(@name) + @name = if seo_name seo_name elsif !homepage_or_about? @@ -141,6 +143,7 @@ module Jekyll def logo @logo ||= begin return unless site["logo"] + if absolute_url? site["logo"] filters.uri_escape site["logo"] else diff --git a/lib/jekyll-seo-tag/image_drop.rb b/lib/jekyll-seo-tag/image_drop.rb index 74c0bf3..32148ed 100644 --- a/lib/jekyll-seo-tag/image_drop.rb +++ b/lib/jekyll-seo-tag/image_drop.rb @@ -18,6 +18,7 @@ module Jekyll # context - the Liquid::Context def initialize(page: nil, context: nil) raise ArgumentError unless page && context + @mutations = {} @page = page @context = context @@ -57,6 +58,7 @@ module Jekyll def absolute_url return unless raw_path return @absolute_url if defined? @absolute_url + @absolute_url = if raw_path.is_a?(String) && absolute_url?(raw_path) == false filters.absolute_url raw_path else diff --git a/lib/jekyll-seo-tag/json_ld_drop.rb b/lib/jekyll-seo-tag/json_ld_drop.rb index 457953f..57b4c25 100644 --- a/lib/jekyll-seo-tag/json_ld_drop.rb +++ b/lib/jekyll-seo-tag/json_ld_drop.rb @@ -34,6 +34,7 @@ module Jekyll def author return unless page_drop.author["name"] + { "@type" => "Person", "name" => page_drop.author["name"], @@ -52,6 +53,7 @@ module Jekyll def publisher return unless logo + output = { "@type" => "Organization", "logo" => { @@ -65,6 +67,7 @@ module Jekyll def main_entity return unless %w(BlogPosting CreativeWork).include?(type) + { "@type" => "WebPage", "@id" => page_drop.canonical_url, diff --git a/lib/jekyll-seo-tag/url_helper.rb b/lib/jekyll-seo-tag/url_helper.rb index ead8e41..68246cd 100644 --- a/lib/jekyll-seo-tag/url_helper.rb +++ b/lib/jekyll-seo-tag/url_helper.rb @@ -13,6 +13,7 @@ module Jekyll # 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? rescue Addressable::URI::InvalidURIError nil