Class: Jekyll::OpenProjectHelpers::IndexPageGenerator

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll-theme-open-project-helpers/filterable_index.rb

Overview

Below passes the ‘items` variable to normal (unfiltered) index page layout.

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/jekyll-theme-open-project-helpers/filterable_index.rb', line 90

def generate(site)
  site.config['max_featured_software'] = 3
  site.config['max_featured_specs'] = 3
  site.config['max_featured_posts'] = 3

  INDEXES.each do |index_name, params|
    if site.config['is_hub']
      collection_name = 'projects'
    else
      collection_name = index_name
    end

    if site.collections.key? collection_name
      # Filters items from given collection_name through item_test function
      # and makes items available in templates via e.g. site.all_specs, site.all_software

      items = get_all_items(site, collection_name, params[:item_test])

      if items.length == 1
        site.config["one_#{index_name}"] = items[0]
      end

      site.config["all_#{index_name}"] = items
      site.config["num_all_#{index_name}"] = items.size

      featured_items = items.select { |item| item.data['feature_with_priority'] != nil }
      site.config["featured_#{index_name}"] = featured_items.sort_by { |item| item.data['feature_with_priority'] }
      site.config["num_featured_#{index_name}"] = featured_items.size

      non_featured_items = items.select { |item| item.data['feature_with_priority'] == nil }
      site.config["non_featured_#{index_name}"] = non_featured_items
      site.config["num_non_featured_#{index_name}"] = non_featured_items.size
    end
  end
end