Class: Jekyll::Pagination
- Defined in:
- lib/jekyll/generators/pagination.rb
Constant Summary
Constants inherited from Plugin
Instance Method Summary collapse
- #generate(site) ⇒ Object
-
#paginate(site, page) ⇒ Object
Paginates the blog’s posts.
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
6 7 8 9 10 |
# File 'lib/jekyll/generators/pagination.rb', line 6 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, ie: page2/index.html, page3/index.html, etc and adds more site-wide data.
+page+ is 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> }
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jekyll/generators/pagination.rb', line 24 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, "page#{num_page}") site.pages << newpage else page.pager = pager end end end |