Class: Jekyll::SeoTag::Drop
- Inherits:
-
Drops::Drop
- Object
- Drops::Drop
- Jekyll::SeoTag::Drop
- Includes:
- UrlHelper
- Defined in:
- lib/jekyll-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
-
#author ⇒ Object
A drop representing the page author.
-
#canonical? ⇒ Boolean
Should the ‘<link rel=“canonical”>` tag be generated for this page?.
- #canonical_url ⇒ Object
- #date_modified ⇒ Object
- #date_published ⇒ Object
- #description ⇒ Object
- #description_max_words ⇒ Object
-
#image ⇒ Object
Returns a Drop representing the page’s image Returns nil if the image has no path, to preserve backwards compatability.
-
#initialize(text, context) ⇒ Drop
constructor
A new instance of Drop.
-
#json_ld ⇒ Object
A drop representing the JSON-LD output.
- #links ⇒ Object
- #logo ⇒ Object
-
#name ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity.
- #page_lang ⇒ Object
- #page_locale ⇒ Object
-
#page_title ⇒ Object
Page title without site title or description appended.
- #site_description ⇒ Object
- #site_tagline ⇒ Object
- #site_tagline_or_description ⇒ Object
- #site_title ⇒ Object
-
#title ⇒ Object
Page title with site title or description appended rubocop:disable Metrics/CyclomaticComplexity.
-
#title? ⇒ Boolean
Should the ‘<title>` tag be generated for this page?.
- #type ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(text, context) ⇒ Drop
Returns a new instance of Drop.
17 18 19 20 21 22 |
# File 'lib/jekyll-seo-tag/drop.rb', line 17 def initialize(text, context) @obj = EMPTY_READ_ONLY_HASH @mutations = {} @text = text @context = context end |
Instance Method Details
#author ⇒ Object
A drop representing the page author
113 114 115 |
# File 'lib/jekyll-seo-tag/drop.rb', line 113 def @author ||= AuthorDrop.new(:page => page, :site => site) end |
#canonical? ⇒ Boolean
Should the ‘<link rel=“canonical”>` tag be generated for this page?
37 38 39 40 41 |
# File 'lib/jekyll-seo-tag/drop.rb', line 37 def canonical? return @canonical if defined?(@canonical) @canonical = (@text !~ %r!canonical=false!i) end |
#canonical_url ⇒ Object
184 185 186 187 188 189 190 191 192 |
# File 'lib/jekyll-seo-tag/drop.rb', line 184 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 ⇒ Object
129 130 131 132 133 134 |
# File 'lib/jekyll-seo-tag/drop.rb', line 129 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 ⇒ Object
136 137 138 |
# File 'lib/jekyll-seo-tag/drop.rb', line 136 def date_published @date_published ||= filters.date_to_xmlschema(page["date"]) if page["date"] end |
#description ⇒ Object
105 106 107 108 109 110 |
# File 'lib/jekyll-seo-tag/drop.rb', line 105 def description @description ||= begin value = format_string(page["description"] || page["excerpt"]) || site_description snippet(value, description_max_words) end end |
#description_max_words ⇒ Object
194 195 196 |
# File 'lib/jekyll-seo-tag/drop.rb', line 194 def description_max_words @description_max_words ||= page["seo_description_max_words"] || 100 end |
#image ⇒ Object
Returns a Drop representing the page’s image Returns nil if the image has no path, to preserve backwards compatability
124 125 126 127 |
# File 'lib/jekyll-seo-tag/drop.rb', line 124 def image @image ||= ImageDrop.new(:page => page, :context => @context) @image if @image.path end |
#json_ld ⇒ Object
A drop representing the JSON-LD output
118 119 120 |
# File 'lib/jekyll-seo-tag/drop.rb', line 118 def json_ld @json_ld ||= JSONLDDrop.new(self) end |
#links ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'lib/jekyll-seo-tag/drop.rb', line 154 def links @links ||= begin if page_seo["links"] page_seo["links"] elsif homepage_or_about? && ["links"] ["links"] end end end |
#logo ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/jekyll-seo-tag/drop.rb', line 164 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 ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/jekyll-seo-tag/drop.rb', line 91 def name return @name if defined?(@name) @name = if seo_name seo_name elsif !homepage_or_about? nil elsif ["name"] format_string ["name"] elsif site_title site_title end end |
#page_lang ⇒ Object
176 177 178 |
# File 'lib/jekyll-seo-tag/drop.rb', line 176 def page_lang @page_lang ||= page["lang"] || site["lang"] || "en_US" end |
#page_locale ⇒ Object
180 181 182 |
# File 'lib/jekyll-seo-tag/drop.rb', line 180 def page_locale @page_locale ||= (page["locale"] || site["locale"] || page_lang).tr("-", "_") end |
#page_title ⇒ Object
Page title without site title or description appended
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/jekyll-seo-tag/drop.rb', line 56 def page_title return @page_title if defined?(@page_title) title = format_string(page["title"]) title_category = format_string(page["title_category"]) @page_title = if title && title_category && title != title_category title + TITLE_SEPARATOR + title_category else title || title_category || site_title end end |
#site_description ⇒ Object
51 52 53 |
# File 'lib/jekyll-seo-tag/drop.rb', line 51 def site_description @site_description ||= format_string site["description"] end |
#site_tagline ⇒ Object
47 48 49 |
# File 'lib/jekyll-seo-tag/drop.rb', line 47 def site_tagline @site_tagline ||= format_string site["tagline"] end |
#site_tagline_or_description ⇒ Object
68 69 70 |
# File 'lib/jekyll-seo-tag/drop.rb', line 68 def site_tagline_or_description site_tagline || site_description end |
#site_title ⇒ Object
43 44 45 |
# File 'lib/jekyll-seo-tag/drop.rb', line 43 def site_title @site_title ||= format_string(site["title"] || site["name"]) end |
#title ⇒ Object
Page title with site title or description appended rubocop:disable Metrics/CyclomaticComplexity
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/jekyll-seo-tag/drop.rb', line 74 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?
29 30 31 32 33 34 |
# 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 ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/jekyll-seo-tag/drop.rb', line 140 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 |