Class: JekyllOpenSdgPlugins::MetaTags

Inherits:
Jekyll::Generator
  • Object
show all
Defined in:
lib/jekyll-open-sdg-plugins/meta_tags.rb

Instance Method Summary collapse

Instance Method Details

#clean_path(path) ⇒ Object



8
9
10
# File 'lib/jekyll-open-sdg-plugins/meta_tags.rb', line 8

def clean_path(path)
  path.delete_prefix('/').delete_suffix('/')
end

#find_metatags_by_path(path, config) ⇒ Object



12
13
14
# File 'lib/jekyll-open-sdg-plugins/meta_tags.rb', line 12

def find_metatags_by_path(path, config)
  config.select { |tag| clean_path(tag['path']) == path }
end

#generate(site) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jekyll-open-sdg-plugins/meta_tags.rb', line 16

def generate(site)

  # Some general variables needed below.
  languages = site.config['languages']
  default_language = languages[0]

  if site.config.has_key?('meta_tags')
    site.collections.keys.each do |collection|
      if collection == 'pages'
        site.collections[collection].docs.each do |doc|
          cleaned_path = clean_path(doc.data['url_by_language'][default_language])
          meta_tags = find_metatags_by_path(cleaned_path, site.config['meta_tags'])
          doc.data['meta_tags'] = meta_tags
        end
      end
    end
  end
end