Class: Bridgetown::SeoTag::Drop
- Inherits:
-
Drops::Drop
- Object
- Drops::Drop
- Bridgetown::SeoTag::Drop
- Includes:
- UrlHelper
- Defined in:
- lib/bridgetown-seo-tag/drop.rb
Constant Summary collapse
- TITLE_SEPARATOR =
" | "- TAGLINE_SEPARATOR =
": "- FORMAT_STRING_METHODS =
[ :markdownify, :strip_html, :normalize_whitespace, :escape_once, ].freeze
- HOMEPAGE_OR_ABOUT_REGEX =
%r!^/(about/)?(index.html?)?$!
Instance Method Summary collapse
-
#author ⇒ Object
A drop representing the page author.
-
#canonical_url ⇒ Object
rubocop:todo Metrics/AbcSize.
- #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 compatibility.
-
#initialize(text, context) ⇒ Drop
constructor
A new instance of Drop.
- #links ⇒ Object
- #logo ⇒ Object
- #name ⇒ Object
- #page_lang ⇒ 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.
-
#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.
15 16 17 18 19 20 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 15 def initialize(text, context) @obj = {} @mutations = {} @text = text @context = context end |
Instance Method Details
#author ⇒ Object
A drop representing the page author
98 99 100 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 98 def @author ||= AuthorDrop.new(page: page, site: site) end |
#canonical_url ⇒ Object
rubocop:todo Metrics/AbcSize
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 160 def canonical_url # rubocop:todo Metrics/AbcSize @canonical_url ||= if page["canonical_url"].to_s.length.positive? page["canonical_url"] elsif page["url"].to_s.length.positive? 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 |
#date_modified ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 109 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 ⇒ Object
122 123 124 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 122 def date_published @date_published ||= filters.date_to_xmlschema(page["date"]) if page["date"] end |
#description ⇒ Object
91 92 93 94 95 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 91 def description @description ||= format_string( page["description"] || page["subtitle"] || page["excerpt"] ) || site_description end |
#image ⇒ Object
Returns a Drop representing the page’s image Returns nil if the image has no path, to preserve backwards compatibility
104 105 106 107 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 104 def image @image ||= ImageDrop.new(page: page, context: @context) @image if @image.path end |
#links ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 138 def links @links ||= if page_seo["links"] page_seo["links"] elsif homepage_or_about? && ["links"] ["links"] end end |
#logo ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 146 def logo @logo ||= if !site.data.dig("site_metadata", "logo") nil elsif 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 |
#name ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 77 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
156 157 158 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 156 def page_lang @page_lang ||= page["lang"] || site["lang"] || "en_US" end |
#page_title ⇒ Object
Page title without site title or description appended
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 50 def page_title @page_title ||= format_string( if (page["title"] == "Index" || page["title"].to_s.empty?) && site_tagline_or_description "#{site_title}#{TAGLINE_SEPARATOR}#{site_tagline_or_description}" else page["title"] end ) || site_title end |
#site_description ⇒ Object
45 46 47 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 45 def site_description @site_description ||= format_string site.data.dig("site_metadata", "description") end |
#site_tagline ⇒ Object
41 42 43 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 41 def site_tagline @site_tagline ||= format_string site.data.dig("site_metadata", "tagline") end |
#site_tagline_or_description ⇒ Object
61 62 63 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 61 def site_tagline_or_description site_tagline || site_description end |
#site_title ⇒ Object
34 35 36 37 38 39 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 34 def site_title @site_title ||= format_string( site.data.dig("site_metadata", "title") || site.data.dig("site_metadata", "name") ) end |
#title ⇒ Object
Page title with site title or description appended
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 66 def title @title ||= if site_title && page_title != site_title && !format_string(page_title).start_with?(site_title + TAGLINE_SEPARATOR) page_title + TITLE_SEPARATOR + site_title else page_title || site_title end @title end |
#title? ⇒ Boolean
Should the ‘<title>` tag be generated for this page?
27 28 29 30 31 32 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 27 def title? return false unless title return @display_title if defined?(@display_title) @display_title = (@text !~ %r!title=false!i) end |
#type ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 126 def type @type ||= if page_seo["type"] page_seo["type"] elsif homepage_or_about? "WebSite" elsif page["date"] "BlogPosting" else "WebPage" end end |
#version ⇒ Object
22 23 24 |
# File 'lib/bridgetown-seo-tag/drop.rb', line 22 def version Bridgetown::SeoTag::VERSION end |