Class: GovukTechDocs::MetaTags

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_tech_docs/meta_tags.rb

Instance Method Summary collapse

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_titleObject



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_urlObject



42
43
44
# File 'lib/govuk_tech_docs/meta_tags.rb', line 42

def canonical_url
  "#{host}#{current_page.url}"
end

#opengraph_tagsObject

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 opengraph_tags
  all_opengraph_tags = {
    "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[all_opengraph_tags.select { |_k, v| v }]
end

#tagsObject



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 tags
  all_tags = {
    "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[all_tags.select { |_k, v| v }]
end