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.
-
#page_title_extention ⇒ Object
Bug fix: original wrote to @site_title_extention, which is the ivar used by ‘site_title_extention` above.
- #site_description ⇒ Object
- #site_title ⇒ Object
- #site_title_extention ⇒ Object
-
#title ⇒ Object
Page title with site title or description appended Removed the redundant trailing ‘@title` line - `||=` already returns the cached/assigned value, so the explicit return was dead code.
-
#title? ⇒ Boolean
Should the ‘<title>` tag be generated for this page?.
- #title_extention_or_description ⇒ Object
- #type ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(text, context) ⇒ Drop
Returns a new instance of Drop.
384 385 386 387 388 389 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 384 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
473 474 475 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 473 def @author ||= AuthorDrop.new(:page => page, :site => site) end |
#canonical_url ⇒ Object
554 555 556 557 558 559 560 561 562 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 554 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
Bug fix: the original was effectively
date = current_time.to_liquid || page["last_modified"].to_liquid
but ‘current_time.to_liquid` is the string returned by strftime, which is always truthy, so `page` was never consulted. The intended precedence is the page’s explicit ‘last_modified` front-matter, falling back to the current build time. Also dropped `Time.new` + `strftime` round trip - `date_to_xmlschema` accepts a Time directly, and the filter formats it consistently with `date_published`.
499 500 501 502 503 504 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 499 def date_modified @date_modified ||= begin date = page["last_modified"] || Time.now filters.date_to_xmlschema(date) if date end end |
#date_published ⇒ Object
506 507 508 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 506 def date_published @date_published ||= filters.date_to_xmlschema(page["date"]) if page["date"] end |
#description ⇒ Object
466 467 468 469 470 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 466 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
484 485 486 487 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 484 def image @image ||= ImageDrop.new(:page => page, :context => @context) @image if @image.path end |
#json_ld ⇒ Object
A drop representing the JSON-LD output
478 479 480 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 478 def json_ld @json_ld ||= JSONLDDrop.new(self) end |
#links ⇒ Object
524 525 526 527 528 529 530 531 532 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 524 def links @links ||= begin if page_seo["links"] page_seo["links"] elsif homepage_or_about? && ["links"] ["links"] end end end |
#logo ⇒ Object
534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 534 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
452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 452 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
546 547 548 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 546 def page_lang @page_lang ||= page["lang"] || site["lang"] || "en_US" end |
#page_locale ⇒ Object
550 551 552 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 550 def page_locale @page_locale ||= (page["locale"] || site["locale"] || page_lang).tr("-", "_") end |
#page_title ⇒ Object
Page title without site title or description appended
408 409 410 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 408 def page_title @page_title ||= format_string page["title"] # || site_title end |
#page_title_extention ⇒ Object
Bug fix: original wrote to @site_title_extention, which is the ivar used by ‘site_title_extention` above. Calling `page_title_extention` first poisoned the site-level cache with the page’s value (and any subsequent call returned the page value when asked for the site value). The correct ivar is
423 424 425 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 423 def page_title_extention @page_title_extention ||= format_string page["title_extention"] end |
#site_description ⇒ Object
427 428 429 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 427 def site_description @site_description ||= format_string site["description"] end |
#site_title ⇒ Object
403 404 405 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 403 def site_title @site_title ||= format_string site["title"] end |
#site_title_extention ⇒ Object
412 413 414 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 412 def site_title_extention @site_title_extention ||= format_string site["title_extention"] end |
#title ⇒ Object
Page title with site title or description appended Removed the redundant trailing ‘@title` line - `||=` already returns the cached/assigned value, so the explicit return was dead code. rubocop:disable Metrics/CyclomaticComplexity
441 442 443 444 445 446 447 448 449 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 441 def title @title ||= begin if page_title != site_title page_title + TITLE_SEPARATOR + title_extention_or_description else site_title + TITLE_SEPARATOR + title_extention_or_description end end end |
#title? ⇒ Boolean
Should the ‘<title>` tag be generated for this page?
396 397 398 399 400 401 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 396 def title? return false unless title return @display_title if defined?(@display_title) @display_title = (@text !~ %r!title=false!i) end |
#title_extention_or_description ⇒ Object
431 432 433 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 431 def title_extention_or_description page_title_extention || site_title_extention || site_description end |
#type ⇒ Object
510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 510 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 |