Class: Jekyll::JekyllFrontAdderGen

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll-frontadder.rb

Overview

Here’s our work horse class

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object

Called by Jekyll to run our plugin



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jekyll-frontadder.rb', line 7

def generate(site)
  # Pickup array of frontmatter things to add up
  frontadd = site.config["frontadder"]
  if frontadd.nil?
    Jekyll.logger.warn 'Frontadder: frontadder not defined in _config.yml, skipping'
    return
  end
  Jekyll.logger.debug 'Frontadder: Will add listed hashes: ', frontadd

  # Initialize hashes for each hash to add
  frontadd.each do |addme|
    site.data[addme] ||= {}
  end

  # For each post, loop through the list of hashes to add and do it.
  site.posts.docs.each do |post|
    Jekyll.logger.debug 'Processing: ', post.url
    frontadd.each do |addme|
      next unless post.data[addme].respond_to?(:merge)
      site.data[addme] = addhashes(site.data[addme], post.data[addme])
      post.data[addme]['runtotal'] = site.data[addme]
    end
  end
end