Class: Jekyll::SeoTag::Drop

Inherits:
Drops::Drop
  • Object
show all
Includes:
Jekyll::SeoTags::UrlHelper
Defined in:
lib/jekyll-seo-tags/drop.rb

Constant Summary collapse

TITLE_SEPARATOR =
" | "
FORMAT_STRING_METHODS =
[
  :markdownify, :strip_html, :normalize_whitespace, :escape_once,
].freeze
HOMEPAGE_OR_ABOUT_REGEX =
%r!^/(about/)?(index.html?)?$!.freeze

Instance Method Summary collapse

Constructor Details

#initialize(text, context) ⇒ Drop

Returns a new instance of Drop.



15
16
17
18
19
20
# File 'lib/jekyll-seo-tags/drop.rb', line 15

def initialize(text, context)
  @obj = EMPTY_READ_ONLY_HASH
  @mutations = {}
  @text = text
  @context = context
end

Instance Method Details

#authorObject

A drop representing the page author



95
96
97
# File 'lib/jekyll-seo-tags/drop.rb', line 95

def author
  @author ||= AuthorDrop.new(:page => page, :site => site)
end

#canonical_urlObject



147
148
149
150
151
152
153
154
155
# File 'lib/jekyll-seo-tags/drop.rb', line 147

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_modifiedObject



106
107
108
109
110
111
# File 'lib/jekyll-seo-tags/drop.rb', line 106

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_publishedObject



113
114
115
# File 'lib/jekyll-seo-tags/drop.rb', line 113

def date_published
  @date_published ||= filters.date_to_xmlschema(page["date"]) if page["date"]
end

#descriptionObject



88
89
90
91
92
# File 'lib/jekyll-seo-tags/drop.rb', line 88

def description
  @description ||= begin
                     format_string(page["description"] || page["excerpt"]) || site_description
                   end
end

#imageObject

Returns a Drop representing the page’s image Returns nil if the image has no path, to preserve backwards compatibility



101
102
103
104
# File 'lib/jekyll-seo-tags/drop.rb', line 101

def image
  @image ||= ImageDrop.new(:page => page, :context => @context)
  @image if @image.path
end


117
118
119
120
121
122
123
124
125
# File 'lib/jekyll-seo-tags/drop.rb', line 117

def links
  @links ||= begin
               if page_seo["links"]
                 page_seo["links"]
               elsif homepage_or_about? && site_social["links"]
                 site_social["links"]
               end
             end
end

#logoObject



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/jekyll-seo-tags/drop.rb', line 127

def 
  @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

#nameObject

rubocop:enable Metrics/CyclomaticComplexity



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/jekyll-seo-tags/drop.rb', line 74

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_langObject



139
140
141
# File 'lib/jekyll-seo-tags/drop.rb', line 139

def page_lang
  @page_lang ||= page["lang"] || site["lang"] || "en_US"
end

#page_localeObject



143
144
145
# File 'lib/jekyll-seo-tags/drop.rb', line 143

def page_locale
  @page_locale ||= (page["locale"] || site["locale"] || page_lang).tr("-", "_")
end

#page_titleObject

Page title without site title or description appended



47
48
49
# File 'lib/jekyll-seo-tags/drop.rb', line 47

def page_title
  @page_title ||= format_string(page["title"]) || site_title
end

#site_descriptionObject



42
43
44
# File 'lib/jekyll-seo-tags/drop.rb', line 42

def site_description
  @site_description ||= format_string site["description"]
end

#site_taglineObject



38
39
40
# File 'lib/jekyll-seo-tags/drop.rb', line 38

def site_tagline
  @site_tagline ||= format_string site["tagline"]
end

#site_tagline_or_descriptionObject



51
52
53
# File 'lib/jekyll-seo-tags/drop.rb', line 51

def site_tagline_or_description
  site_tagline || site_description
end

#site_titleObject



34
35
36
# File 'lib/jekyll-seo-tags/drop.rb', line 34

def site_title
  @site_title ||= format_string(site["title"] || site["name"])
end

#titleObject

Page title with site title or description appended rubocop:disable Metrics/CyclomaticComplexity



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/jekyll-seo-tags/drop.rb', line 57

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?Boolean

Should the ‘<title>` tag be generated for this page?

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/jekyll-seo-tags/drop.rb', line 27

def title?
  return false unless title
  return @display_title if defined?(@display_title)

  @display_title = (@text !~ %r!title=false!i)
end

#versionObject



22
23
24
# File 'lib/jekyll-seo-tags/drop.rb', line 22

def version
  Jekyll::SeoTags::VERSION
end