Class: Bunto::SeoTag::Drop
- Inherits:
-
Drops::Drop
- Object
- Drops::Drop
- Bunto::SeoTag::Drop
- Includes:
- JSONLD
- Defined in:
- lib/bunto-seo-tag/drop.rb
Constant Summary collapse
- TITLE_SEPARATOR =
" | ".freeze
- FORMAT_STRING_METHODS =
%i[ markdownify strip_html normalize_whitespace escape_once ].freeze
- HOMEPAGE_OR_ABOUT_REGEX =
%r!^/(about/)?(index.html?)?$!
Constants included from JSONLD
Instance Method Summary collapse
-
#author ⇒ Object
Returns a nil or a hash representing the author Author name will be pulled from:.
- #canonical_url ⇒ Object
- #date_modified ⇒ Object
- #date_published ⇒ Object
- #description ⇒ Object
-
#image ⇒ Object
Returns nil or a hash representing the page image The image hash will always contain a path, pulled from:.
-
#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_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
Methods included from JSONLD
Constructor Details
#initialize(text, context) ⇒ Drop
Returns a new instance of Drop.
12 13 14 15 16 17 |
# File 'lib/bunto-seo-tag/drop.rb', line 12 def initialize(text, context) @obj = {} @mutations = {} @text = text @context = context end |
Instance Method Details
#author ⇒ Object
Returns a nil or a hash representing the author Author name will be pulled from:
-
The ‘author` key, if the key is a string
-
The first author in the ‘authors` key
-
The ‘author` key in the site config
If the result from the name search is a string, we’ll also check to see if the author exists in ‘site.data.authors`
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bunto-seo-tag/drop.rb', line 84 def @author ||= begin return if .to_s.empty? = if .is_a?(String) () else end ["twitter"] ||= ["name"] ["twitter"].delete! "@" if ["twitter"] .to_liquid end end |
#canonical_url ⇒ Object
184 185 186 187 188 189 190 191 192 |
# File 'lib/bunto-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
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/bunto-seo-tag/drop.rb', line 100 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
113 114 115 |
# File 'lib/bunto-seo-tag/drop.rb', line 113 def date_published @date_published ||= filters.date_to_xmlschema(page["date"]) if page["date"] end |
#description ⇒ Object
69 70 71 72 73 |
# File 'lib/bunto-seo-tag/drop.rb', line 69 def description @description ||= begin format_string(page["description"] || page["excerpt"]) || site_description end end |
#image ⇒ Object
Returns nil or a hash representing the page image The image hash will always contain a path, pulled from:
-
The ‘image` key if it’s a string
-
The ‘image.path` key if it’s a hash
-
The ‘image.facebook` key
-
The ‘image.twitter` key
The resulting path is always an absolute URL
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/bunto-seo-tag/drop.rb', line 161 def image return @image if defined?(@image) image = page["image"] return @image = nil unless image image = { "path" => image } if image.is_a?(String) image["path"] ||= image["facebook"] || image["twitter"] return @image = nil unless image["path"] unless absolute_url? image["path"] image["path"] = filters.absolute_url image["path"] end image["path"] = filters.uri_escape image["path"] @image = image.to_liquid end |
#links ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/bunto-seo-tag/drop.rb', line 131 def links @links ||= begin if page_seo["links"] page_seo["links"] elsif homepage_or_about? && ["links"] ["links"] end end end |
#logo ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/bunto-seo-tag/drop.rb', line 141 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
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bunto-seo-tag/drop.rb', line 56 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
180 181 182 |
# File 'lib/bunto-seo-tag/drop.rb', line 180 def page_lang @page_lang ||= page["lang"] || site["lang"] || "en_US" end |
#page_title ⇒ Object
Page title without site title or description appended
39 40 41 |
# File 'lib/bunto-seo-tag/drop.rb', line 39 def page_title @page_title ||= format_string(page["title"]) || site_title end |
#site_description ⇒ Object
34 35 36 |
# File 'lib/bunto-seo-tag/drop.rb', line 34 def site_description @site_description ||= format_string site["description"] end |
#site_title ⇒ Object
30 31 32 |
# File 'lib/bunto-seo-tag/drop.rb', line 30 def site_title @site_title ||= format_string(site["title"] || site["name"]) end |
#title ⇒ Object
Page title with site title or description appended
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bunto-seo-tag/drop.rb', line 44 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_description else page_title || site_title end end end |
#title? ⇒ Boolean
Should the ‘<title>` tag be generated for this page?
24 25 26 27 28 |
# File 'lib/bunto-seo-tag/drop.rb', line 24 def title? return false unless title return @display_title if defined?(@display_title) @display_title = (@text !~ %r!title=false!i) end |
#type ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/bunto-seo-tag/drop.rb', line 117 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 |