class Jekyll::SeoTag::Drop

Constants

EMPTY_READ_ONLY_HASH
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 17
def initialize(text, context)
  @obj = EMPTY_READ_ONLY_HASH
  @mutations = {}
  @text = text
  @context = context
end

Public Instance Methods

author() click to toggle source

A drop representing the page author

# File lib/jekyll-seo-tag/drop.rb, line 97
def author
  @author ||= AuthorDrop.new(:page => page, :site => site)
end
canonical_url() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 168
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 113
def date_modified
  @date_modified ||= begin
    date = page_seo["date_modified"] || page["last_modified_at"].to_liquid || page["date"]
    filters.date_to_xmlschema(date) if date
  end
end
date_published() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 120
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 90
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 108
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 102
def json_ld
  @json_ld ||= JSONLDDrop.new(self)
end
name() click to toggle source

rubocop:enable Metrics/CyclomaticComplexity

# File lib/jekyll-seo-tag/drop.rb, line 76
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 160
def page_lang
  @page_lang ||= page["lang"] || site["lang"] || "en_US"
end
page_locale() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 164
def page_locale
  @page_locale ||= (page["locale"] || site["locale"] || page_lang).tr("-", "_")
end
page_title() click to toggle source

Page title without site title or description appended

# File lib/jekyll-seo-tag/drop.rb, line 49
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 44
def site_description
  @site_description ||= format_string site["description"]
end
site_tagline() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 40
def site_tagline
  @site_tagline ||= format_string site["tagline"]
end
site_tagline_or_description() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 53
def site_tagline_or_description
  site_tagline || site_description
end
site_title() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 36
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 59
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_tagline_or_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 29
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 124
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 24
def version
  Jekyll::SeoTag::VERSION
end

Private Instance Methods

fallback_data() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 208
def fallback_data
  @fallback_data ||= {}
end
filters() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 180
def filters
  @filters ||= Jekyll::SeoTag::Filters.new(@context)
end
format_string(string) click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 212
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 192
def homepage_or_about?
  page["url"] =~ HOMEPAGE_OR_ABOUT_REGEX
end
page() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 184
def page
  @page ||= @context.registers[:page].to_liquid
end
page_number() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 196
def page_number
  return unless @context["paginator"] && @context["paginator"]["page"]

  current = @context["paginator"]["page"]
  total = @context["paginator"]["total_pages"]
  paginator_message = site["seo_paginator_message"] || "Page %<current>s of %<total>s for "

  format(paginator_message, :current => current, :total => total) if current > 1
end
page_seo() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 224
def page_seo
  @page_seo ||= sub_hash(page, "seo")
end
seo_name() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 220
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 188
def site
  @site ||= @context.registers[:site].site_payload["site"].to_liquid
end
site_social() click to toggle source
# File lib/jekyll-seo-tag/drop.rb, line 228
def site_social
  @site_social ||= sub_hash(site, "social")
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 238
def sub_hash(hash, key)
  if hash[key].is_a?(Hash)
    hash[key]
  else
    EMPTY_READ_ONLY_HASH
  end
end