Class: Jekyll::Pagination

Inherits:
Generator show all
Defined in:
lib/jekyll/generators/pagination.rb

Constant Summary

Constants inherited from Plugin

Jekyll::Plugin::PRIORITIES

Instance Method Summary collapse

Methods inherited from Plugin

<=>, inherited, #initialize, priority, safe, subclasses

Constructor Details

This class inherits a constructor from Jekyll::Plugin

Instance Method Details

#generate(site) ⇒ Object

Generate paginated pages if necessary.

site - The Site.

Returns nothing.



12
13
14
15
16
# File 'lib/jekyll/generators/pagination.rb', line 12

def generate(site)
  site.pages.dup.each do |page|
    paginate(site, page) if Pager.pagination_enabled?(site.config, page.name)
  end
end

#paginate(site, page) ⇒ Object

Paginates the blog’s posts. Renders the index.html file into paginated directories, e.g.: page2/index.html, page3/index.html, etc and adds more site-wide data.

site - The Site. page - The index.html Page that requires pagination.

=> { “page” => <Number>,

"per_page" => <Number>,
"posts" => [<Post>],
"total_posts" => <Number>,
"total_pages" => <Number>,
"previous_page" => <Number>,
"next_page" => <Number> }


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jekyll/generators/pagination.rb', line 32

def paginate(site, page)
  all_posts = site.site_payload['site']['posts']
  pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i)
  (1..pages).each do |num_page|
    pager = Pager.new(site.config, num_page, all_posts, pages)
    if num_page > 1
      newpage = Page.new(site, site.source, page.dir, page.name)
      newpage.pager = pager
      newpage.dir = File.join(page.dir, paginate_path(site, num_page))
      site.pages << newpage
    else
      page.pager = pager
    end
  end
end