Class: GovukTechDocs::MetaTags
- Inherits:
-
Object
- Object
- GovukTechDocs::MetaTags
- Defined in:
- lib/govuk_tech_docs/meta_tags.rb
Instance Method Summary collapse
- #browser_title ⇒ Object
- #canonical_url ⇒ Object
-
#initialize(config, current_page) ⇒ MetaTags
constructor
A new instance of MetaTags.
-
#opengraph_tags ⇒ Object
OpenGraph uses the non-standard property attribute instead of name, so we return these separately so we can output them correctly.
- #tags ⇒ Object
Constructor Details
#initialize(config, current_page) ⇒ MetaTags
Returns a new instance of MetaTags.
3 4 5 6 |
# File 'lib/govuk_tech_docs/meta_tags.rb', line 3 def initialize(config, current_page) @config = config @current_page = current_page end |
Instance Method Details
#browser_title ⇒ Object
38 39 40 |
# File 'lib/govuk_tech_docs/meta_tags.rb', line 38 def browser_title [page_title, site_name].select(&:present?).uniq.join(" - ") end |
#canonical_url ⇒ Object
42 43 44 |
# File 'lib/govuk_tech_docs/meta_tags.rb', line 42 def canonical_url "#{host}#{current_page.url}" end |
#opengraph_tags ⇒ Object
OpenGraph uses the non-standard property attribute instead of name, so we return these separately so we can output them correctly.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/govuk_tech_docs/meta_tags.rb', line 25 def = { "og:description" => page_description, "og:image" => page_image, "og:site_name" => site_name, "og:title" => page_title, "og:type" => "object", "og:url" => canonical_url, } Hash[.select { |_k, v| v }] end |
#tags ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/govuk_tech_docs/meta_tags.rb', line 8 def = { "description" => page_description, "google-site-verification" => google_site_verification, "robots" => robots, "twitter:card" => "summary", "twitter:domain" => URI.parse(host).host, "twitter:image" => page_image, "twitter:title" => browser_title, "twitter:url" => canonical_url, } Hash[.select { |_k, v| v }] end |