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



27
28
29
# File 'lib/govuk_tech_docs/meta_tags.rb', line 27

def browser_title
  [page_title, site_name].select(&:present?).uniq.join(' | ')
end

#canonical_urlObject



31
32
33
# File 'lib/govuk_tech_docs/meta_tags.rb', line 31

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

#tagsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/govuk_tech_docs/meta_tags.rb', line 8

def tags
  all_tags = {
    'description' => page_description,
    'og:description' => page_description,
    'og:image' => page_image,
    'og:site_name' => site_name,
    'og:title' => page_title,
    'og:type' => 'object',
    'og:url' => canonical_url,
    '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