Class: Jekyll::SeoTag::Drop

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(text, context) ⇒ Drop

Returns a new instance of Drop.



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

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

Instance Method Details

#authorObject

A drop representing the page author



78
79
80
# File 'lib/jekyll-seo-tag/drop.rb', line 78

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

#canonical_urlObject



150
151
152
153
154
155
156
157
158
# File 'lib/jekyll-seo-tag/drop.rb', line 150

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



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/jekyll-seo-tag/drop.rb', line 94

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_publishedObject



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

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

#descriptionObject



71
72
73
74
75
# File 'lib/jekyll-seo-tag/drop.rb', line 71

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 compatability



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

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

#json_ldObject

A drop representing the JSON-LD output



83
84
85
# File 'lib/jekyll-seo-tag/drop.rb', line 83

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


125
126
127
128
129
130
131
132
133
# File 'lib/jekyll-seo-tag/drop.rb', line 125

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



135
136
137
138
139
140
141
142
143
144
# File 'lib/jekyll-seo-tag/drop.rb', line 135

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



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

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



146
147
148
# File 'lib/jekyll-seo-tag/drop.rb', line 146

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

#page_titleObject

Page title without site title or description appended



41
42
43
# File 'lib/jekyll-seo-tag/drop.rb', line 41

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

#site_descriptionObject



36
37
38
# File 'lib/jekyll-seo-tag/drop.rb', line 36

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

#site_titleObject



32
33
34
# File 'lib/jekyll-seo-tag/drop.rb', line 32

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

#titleObject

Page title with site title or description appended



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jekyll-seo-tag/drop.rb', line 46

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
end

#title?Boolean

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

Returns:

  • (Boolean)


26
27
28
29
30
# 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

#typeObject



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/jekyll-seo-tag/drop.rb', line 111

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



21
22
23
# File 'lib/jekyll-seo-tag/drop.rb', line 21

def version
  Jekyll::SeoTag::VERSION
end