Class: JekyllOpenSdgPlugins::CreateGoals

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

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jekyll-open-sdg-plugins/create_goals.rb', line 8

def generate(site)
  # If site.create_goals is set, create goals per the metadata.
  if site.config['languages'] and site.config['create_goals']
    # Compile the list of goals.
    goals = {}
    site.data['meta'].each do |inid, meta|
      goal = inid.split('-')[0].to_i
      goals[goal] = true
    end
    # Decide what layout to use for the goal pages.
    layout = 'goal'
    if site.config['create_goals'].key?('layout')
      layout = site.config['create_goals']['layout']
    end
    # Loop through the languages.
    site.config['languages'].each_with_index do |language, index|
      # Loop through the goals.
      goals.sort.each do |goal, value|
        # Add the language subfolder for all except the default (first) language.
        dir = index == 0 ? goal.to_s : File.join(language, goal.to_s)
        # Create the goal page.
        site.collections['goals'].docs << GoalPage.new(site, site.source, dir, goal, language, layout)
      end
    end
  end
end