class Bridgetown::SeoTag::Drop
Constants
- FORMAT_STRING_METHODS
- HOMEPAGE_OR_ABOUT_REGEX
- TITLE_SEPARATOR
Attributes
context[R]
Public Class Methods
new(text, context)
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 14 def initialize(text, context) @obj = {} @mutations = {} @text = text @context = context end
Public Instance Methods
canonical_url()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 167 def canonical_url @canonical_url ||= begin if page["canonical_url"].to_s.present? page["canonical_url"] elsif page["url"].to_s.present? filters.absolute_url(page["url"]).to_s.gsub(%r!/index\.html$!, "/") else filters.absolute_url(page["relative_url"]).to_s.gsub(%r!/index\.html$!, "/") end end end
date_modified()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 110 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_published()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 123 def date_published @date_published ||= filters.date_to_xmlschema(page["date"]) if page["date"] end
description()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 90 def description @description ||= begin format_string( page["description"] || page["subtitle"] || page["excerpt"] ) || site_description end end
image()
click to toggle source
Returns a Drop
representing the page's image Returns nil if the image has no path, to preserve backwards compatability
# File lib/bridgetown-seo-tag/drop.rb, line 105 def image @image ||= ImageDrop.new(page: page, context: @context) @image if @image.path end
links()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 141 def links @links ||= begin if page_seo["links"] page_seo["links"] elsif homepage_or_about? && site_social["links"] site_social["links"] end end end
logo()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 151 def logo @logo ||= begin return unless site.data.dig("site_metadata", "logo") if absolute_url? site.data.dig("site_metadata", "logo") filters.uri_escape site.data.dig("site_metadata", "logo") else filters.uri_escape filters.absolute_url site.data.dig("site_metadata", "logo") end end end
name()
click to toggle source
rubocop:enable Metrics/CyclomaticComplexity
# File lib/bridgetown-seo-tag/drop.rb, line 76 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_lang()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 163 def page_lang @page_lang ||= page["lang"] || site["lang"] || "en_US" end
page_title()
click to toggle source
Page title without site title or description appended
# File lib/bridgetown-seo-tag/drop.rb, line 49 def page_title @page_title ||= format_string(page["title"]) || site_title end
site_description()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 44 def site_description @site_description ||= format_string site.data.dig("site_metadata", "description") end
site_tagline()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 40 def site_tagline @site_tagline ||= format_string site.data.dig("site_metadata", "tagline") end
site_tagline_or_description()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 53 def site_tagline_or_description site_tagline || site_description end
site_title()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 33 def site_title @site_title ||= format_string( site.data.dig("site_metadata", "title") || site.data.dig("site_metadata", "name") ) end
title()
click to toggle source
Page title with site title or description appended rubocop:disable Metrics/CyclomaticComplexity
# File lib/bridgetown-seo-tag/drop.rb, line 59 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?()
click to toggle source
Should the `<title>` tag be generated for this page?
# File lib/bridgetown-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
type()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 127 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()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 21 def version Bridgetown::SeoTag::VERSION end
Private Instance Methods
fallback_data()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 209 def fallback_data @fallback_data ||= {} end
filters()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 181 def filters @filters ||= Bridgetown::SeoTag::Filters.new(@context) end
format_string(string)
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 213 def format_string(string) string = FORMAT_STRING_METHODS.reduce(string) do |memo, method| filters.public_send(method, memo) end string unless string.empty? end
homepage_or_about?()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 193 def homepage_or_about? page["url"] =~ HOMEPAGE_OR_ABOUT_REGEX end
page()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 185 def page @page ||= @context.registers[:page].to_liquid end
page_number()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 197 def page_number return unless @context["paginator"] && @context["paginator"]["page"] current = @context["paginator"]["page"] total = @context["paginator"]["total_pages"] paginator_message = site["seo_paginator_message"] || "Page %<current>s of %<total>s for " format(paginator_message, current: current, total: total) if current > 1 end
page_seo()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 225 def page_seo @page_seo ||= sub_hash(page, "seo") end
seo_name()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 221 def seo_name @seo_name ||= format_string(page_seo["name"]) if page_seo["name"] end
site()
click to toggle source
# File lib/bridgetown-seo-tag/drop.rb, line 189 def site @site ||= @context.registers[:site].site_payload["site"].to_liquid end
sub_hash(hash, key)
click to toggle source
Safely returns a sub hash
hash - the parent hash key - the key in the parent hash
Returns the sub hash or an empty hash, if it does not exist
# File lib/bridgetown-seo-tag/drop.rb, line 239 def sub_hash(hash, key) if hash && hash[key].is_a?(Hash) hash[key] else {} end end