class Jekyll::SeoTag::Drop
Constants
- FORMAT_STRING_METHODS
- HOMEPAGE_OR_ABOUT_REGEX
- TITLE_SEPARATOR
Attributes
context[R]
Public Class Methods
new(text, context)
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 14 def initialize(text, context) @obj = {} @mutations = {} @text = text @context = context end
Public Instance Methods
canonical_url()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 159 def canonical_url @canonical_url ||= begin if page["canonical_url"].to_s.empty? filters.absolute_url(page["url"]).to_s.gsub(%r!/index\.html$!, "/") else page["canonical_url"] end end end
date_modified()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 102 def date_modified @date_modified ||= begin date = if page_seo["date_modified"] page_seo["date_modified"] elsif page["last_modified_at"] page["last_modified_at"].to_liquid else page["date"] end filters.date_to_xmlschema(date) if date end end
date_published()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 115 def date_published @date_published ||= filters.date_to_xmlschema(page["date"]) if page["date"] end
description()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 79 def description @description ||= begin format_string(page["description"] || page["excerpt"]) || site_description end end
image()
click to toggle source
Returns a Drop
representing the page's image Returns nil if the image has no path, to preserve backwards compatability
# File lib/jekyll-seo-tag/drop.rb, line 97 def image @image ||= ImageDrop.new(:page => page, :context => @context) @image if @image.path end
json_ld()
click to toggle source
A drop representing the JSON-LD output
# File lib/jekyll-seo-tag/drop.rb, line 91 def json_ld @json_ld ||= JSONLDDrop.new(self) end
links()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 133 def links @links ||= begin if page_seo["links"] page_seo["links"] elsif homepage_or_about? && site_social["links"] site_social["links"] end end end
logo()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 143 def logo @logo ||= begin return unless site["logo"] if absolute_url? site["logo"] filters.uri_escape site["logo"] else filters.uri_escape filters.absolute_url site["logo"] end end end
name()
click to toggle source
rubocop:enable Metrics/CyclomaticComplexity
# File lib/jekyll-seo-tag/drop.rb, line 65 def name return @name if defined?(@name) @name = if seo_name seo_name elsif !homepage_or_about? nil elsif site_social["name"] format_string site_social["name"] elsif site_title site_title end end
page_lang()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 155 def page_lang @page_lang ||= page["lang"] || site["lang"] || "en_US" end
page_title()
click to toggle source
Page title without site title or description appended
# File lib/jekyll-seo-tag/drop.rb, line 42 def page_title @page_title ||= format_string(page["title"]) || site_title end
site_description()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 37 def site_description @site_description ||= format_string site["description"] end
site_title()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 33 def site_title @site_title ||= format_string(site["title"] || site["name"]) end
title()
click to toggle source
Page title with site title or description appended rubocop:disable Metrics/CyclomaticComplexity
# File lib/jekyll-seo-tag/drop.rb, line 48 def title @title ||= begin if site_title && page_title != site_title page_title + TITLE_SEPARATOR + site_title elsif site_description && site_title site_title + TITLE_SEPARATOR + site_description else page_title || site_title end end return page_number + @title if page_number @title end
title?()
click to toggle source
Should the `<title>` tag be generated for this page?
# File lib/jekyll-seo-tag/drop.rb, line 26 def title? return false unless title return @display_title if defined?(@display_title) @display_title = (@text !~ %r!title=false!i) end
type()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 119 def type @type ||= begin if page_seo["type"] page_seo["type"] elsif homepage_or_about? "WebSite" elsif page["date"] "BlogPosting" else "WebPage" end end end
version()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 21 def version Jekyll::SeoTag::VERSION end
Private Instance Methods
fallback_data()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 198 def fallback_data @fallback_data ||= {} end
filters()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 171 def filters @filters ||= Jekyll::SeoTag::Filters.new(@context) end
format_string(string)
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 202 def format_string(string) string = FORMAT_STRING_METHODS.reduce(string) do |memo, method| filters.public_send(method, memo) end string unless string.empty? end
homepage_or_about?()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 183 def homepage_or_about? page["url"] =~ HOMEPAGE_OR_ABOUT_REGEX end
page()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 175 def page @page ||= @context.registers[:page].to_liquid end
page_number()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 187 def page_number return unless @context["paginator"] && @context["paginator"]["page"] current = @context["paginator"]["page"] total = @context["paginator"]["total_pages"] return "Page #{current} of #{total} for " if current > 1 end
page_seo()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 214 def page_seo @page_seo ||= sub_hash(page, "seo") end
seo_name()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 210 def seo_name @seo_name ||= format_string(page_seo["name"]) if page_seo["name"] end
site()
click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 179 def site @site ||= @context.registers[:site].site_payload["site"].to_liquid end
sub_hash(hash, key)
click to toggle source
Safely returns a sub hash
hash - the parent hash key - the key in the parent hash
Returns the sub hash or an empty hash, if it does not exist
# File lib/jekyll-seo-tag/drop.rb, line 228 def sub_hash(hash, key) if hash[key].is_a?(Hash) hash[key] else {} end end