Class: Jekyll::AemiSeoTag::Drop

Inherits:
Drops::Drop
  • Object
show all
Includes:
UrlHelper
Defined in:
lib/aemi-seo-tag/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.



17
18
19
20
21
22
# File 'lib/aemi-seo-tag/drop.rb', line 17

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



107
108
109
# File 'lib/aemi-seo-tag/drop.rb', line 107

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

#canonical_urlObject



183
184
185
186
187
188
189
190
191
# File 'lib/aemi-seo-tag/drop.rb', line 183

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

#commentsObject



33
34
35
36
# File 'lib/aemi-seo-tag/drop.rb', line 33

def comments
  return false unless comments
  return true if comments
end

#date_modifiedObject



128
129
130
131
132
133
# File 'lib/aemi-seo-tag/drop.rb', line 128

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



135
136
137
# File 'lib/aemi-seo-tag/drop.rb', line 135

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

#descriptionObject



100
101
102
103
104
# File 'lib/aemi-seo-tag/drop.rb', line 100

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

#generatorObject



28
29
30
31
# File 'lib/aemi-seo-tag/drop.rb', line 28

def generator
  return false unless generator
  return true if generator
end

#imageObject

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



123
124
125
126
# File 'lib/aemi-seo-tag/drop.rb', line 123

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

#json_ldObject

A drop representing the JSON-LD output



117
118
119
# File 'lib/aemi-seo-tag/drop.rb', line 117

def json_ld
  @json_ld ||= JSONLDDrop.new(self)
end

#jsonldObject



111
112
113
114
# File 'lib/aemi-seo-tag/drop.rb', line 111

def jsonld
  return true unless generator
  return false if generator == false
end


153
154
155
156
157
158
159
160
161
# File 'lib/aemi-seo-tag/drop.rb', line 153

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



163
164
165
166
167
168
169
170
171
172
173
# File 'lib/aemi-seo-tag/drop.rb', line 163

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



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/aemi-seo-tag/drop.rb', line 86

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



175
176
177
# File 'lib/aemi-seo-tag/drop.rb', line 175

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

#page_localeObject



179
180
181
# File 'lib/aemi-seo-tag/drop.rb', line 179

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

#page_titleObject

Page title without site title or description appended



59
60
61
# File 'lib/aemi-seo-tag/drop.rb', line 59

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

#site_descriptionObject



54
55
56
# File 'lib/aemi-seo-tag/drop.rb', line 54

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

#site_taglineObject



50
51
52
# File 'lib/aemi-seo-tag/drop.rb', line 50

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

#site_tagline_or_descriptionObject



63
64
65
# File 'lib/aemi-seo-tag/drop.rb', line 63

def site_tagline_or_description
  site_tagline || site_description
end

#site_titleObject



46
47
48
# File 'lib/aemi-seo-tag/drop.rb', line 46

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



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/aemi-seo-tag/drop.rb', line 69

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)


39
40
41
42
43
44
# File 'lib/aemi-seo-tag/drop.rb', line 39

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

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

#typeObject



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/aemi-seo-tag/drop.rb', line 139

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

#versionObject



24
25
26
# File 'lib/aemi-seo-tag/drop.rb', line 24

def version
  Jekyll::AemiSeoTag::VERSION
end