Class: Jekyll::SeoTag::Drop
- Inherits:
-
Drops::Drop
- Object
- Drops::Drop
- Jekyll::SeoTag::Drop
- Includes:
- UrlHelper
- Defined in:
- lib/starter_web/_plugins/seo/j1-seo-tags.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_url ⇒ Object
- #date_modified ⇒ Object
- #date_published ⇒ Object
- #description ⇒ 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.
287 288 289 290 291 292 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 287 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
367 368 369 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 367 def ||= AuthorDrop.new(:page => page, :site => site) end |
#canonical_url ⇒ Object
438 439 440 441 442 443 444 445 446 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 438 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
383 384 385 386 387 388 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 383 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
390 391 392 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 390 def date_published @date_published ||= filters.date_to_xmlschema(page["date"]) if page["date"] end |
#description ⇒ Object
360 361 362 363 364 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 360 def description @description ||= begin format_string(page["description"] || page["excerpt"]) || site_description end end |
#image ⇒ Object
Returns a Drop representing the page’s image Returns nil if the image has no path, to preserve backwards compatability
378 379 380 381 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 378 def image @image ||= ImageDrop.new(:page => page, :context => @context) @image if @image.path end |
#json_ld ⇒ Object
A drop representing the JSON-LD output
372 373 374 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 372 def json_ld @json_ld ||= JSONLDDrop.new(self) end |
#links ⇒ Object
408 409 410 411 412 413 414 415 416 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 408 def links @links ||= begin if page_seo["links"] page_seo["links"] elsif homepage_or_about? && ["links"] ["links"] end end end |
#logo ⇒ Object
418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 418 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
346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 346 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
430 431 432 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 430 def page_lang @page_lang ||= page["lang"] || site["lang"] || "en_US" end |
#page_locale ⇒ Object
434 435 436 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 434 def page_locale @page_locale ||= (page["locale"] || site["locale"] || page_lang).tr("-", "_") end |
#page_title ⇒ Object
Page title without site title or description appended
319 320 321 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 319 def page_title @page_title ||= format_string(page["title"]) || site_title end |
#site_description ⇒ Object
314 315 316 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 314 def site_description @site_description ||= format_string site["description"] end |
#site_tagline ⇒ Object
310 311 312 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 310 def site_tagline @site_tagline ||= format_string site["tagline"] end |
#site_tagline_or_description ⇒ Object
323 324 325 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 323 def site_tagline_or_description site_tagline || site_description end |
#site_title ⇒ Object
306 307 308 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 306 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
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 329 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?
299 300 301 302 303 304 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 299 def title? return false unless title return @display_title if defined?(@display_title) @display_title = (@text !~ %r!title=false!i) end |
#type ⇒ Object
394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 394 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 ⇒ Object
294 295 296 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 294 def version Jekyll::SeoTag::VERSION end |