Class: Jekyll::CollectionPages::CollectionPager

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/collection_pages/collection_pager.rb

Instance Method Summary collapse

Constructor Details

#initialize(site, config) ⇒ CollectionPager

Returns a new instance of CollectionPager.



6
7
8
9
10
11
12
13
14
# File 'lib/jekyll/collection_pages/collection_pager.rb', line 6

def initialize(site, config)
  @site = site
  @config = config
  @tags_with_docs = sorted_tags(site, config.collection_name, config.tag_field)
  path_template = PathTemplate.new(raw_template: config.tag_base_path, tag_field: config.tag_field, collection_name: config.collection_name,
                                   require_num: !config.per_page.nil? && config.per_page.positive?)
  @template = path_template.template
  @permalink = TagPath.new(@template, ':field', slugify_value: false).url_for(1)
end

Instance Method Details

#create_pagesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jekyll/collection_pages/collection_pager.rb', line 16

def create_pages
  documents_map = {}
   = {}
  @tags_with_docs.each do |tag, posts_with_tag|
    page_count = TagPager.calculate_pages(posts_with_tag, @config.per_page)
    tag_pages = []
    (1..page_count).each do |page_num|
      tag_page = build_page(@site, tag, posts_with_tag, page_num)
      @site.pages << tag_page
      tag_pages << tag_page
    end
    documents_map[tag] = posts_with_tag
    [tag] = {
      'pages' => tag_pages,
      'index' => tag_pages.first
    }
    Jekyll.logger.info('CollectionPages:',
                       "Generated #{tag_pages.size} page(s) for tag '#{tag}' in collection '#{@config.collection_name}'.")
  end

  (documents_map, )
end