Class: Jekyll::Itafroma::ArchiveGenerator

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll/itafroma/archive_generator.rb

Overview

Generator for archive listings.

Constant Summary collapse

DEFAULT_LAYOUT =
'archive'
DEFAULT_PATH =
'/'
DEFAULT_TITLE =
'Blog archive'
DEFAULT_INCLUSIONS =
{}
DEFAULT_EXCLUSIONS =
{}

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object

Generate archive pages.

site - The site.

Returns nothing.


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jekyll/itafroma/archive_generator.rb', line 29

def generate(site)
  archives = site.config['archive'] || []

  if archives.is_a? Hash
    warn 'The configuration format used for Jekyll Archive Generator is deprecated. Please see README for the new format.'
    archives = [archives]
  end

  archives.each do |archive|
    layout = archive['layout'] || DEFAULT_LAYOUT
    if site.layouts.key? layout
      path = archive['path'] || DEFAULT_PATH
      title = archive['title'] || DEFAULT_TITLE

      inclusions = archive['include'] || DEFAULT_INCLUSIONS
      posts = site.posts.dup
      inclusions.any? do |key, inclusion|
        posts.select! do |post|
          (post[key] & inclusion).any?
        end
      end

      exclusions = archive['exclude'] || DEFAULT_EXCLUSIONS
      exclusions.each do |key, exclusion|
        posts.reject! do |post|
          (post[key] & exclusion).any?
        end
      end

      site.pages += generate_archive_pages(site, posts, layout, path, title)
    end
  end
end