Class: Paginate::Pagination
- Inherits:
-
Jekyll::Generator
- Object
- Jekyll::Generator
- Paginate::Pagination
- Defined in:
- lib/fenton-jekyll-plugin/jb_jekyll_paging.rb
Class Method Summary collapse
-
.first_page_url(site) ⇒ Object
Static: Fetch the URL of the template page.
-
.template_page(site) ⇒ Object
Public: Find the Jekyll::Page which will act as the pager template.
Instance Method Summary collapse
-
#generate(site) ⇒ Object
Generate paginated pages if necessary.
-
#paginate(site, page) ⇒ Object
Paginates the blog’s posts.
Class Method Details
.first_page_url(site) ⇒ Object
Static: Fetch the URL of the template page. Used to determine the
path to the first pager in the series.
site - the Jekyll::Site object
Returns the url of the template page
55 56 57 58 59 60 61 |
# File 'lib/fenton-jekyll-plugin/jb_jekyll_paging.rb', line 55 def self.first_page_url(site) if page = Pagination.template_page(site) page.url else nil end end |
.template_page(site) ⇒ Object
Public: Find the Jekyll::Page which will act as the pager template
site - the Jekyll::Site object
Returns the Jekyll::Page which will act as the pager template
68 69 70 71 72 73 74 |
# File 'lib/fenton-jekyll-plugin/jb_jekyll_paging.rb', line 68 def self.template_page(site) site.pages.select do |page| Pager.pagination_candidate?(site.config, page) end.sort do |one, two| two.path.size <=> one.path.size end.first end |
Instance Method Details
#generate(site) ⇒ Object
Generate paginated pages if necessary. site - The Site.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fenton-jekyll-plugin/jb_jekyll_paging.rb', line 8 def generate(site) if Pager.pagination_enabled?(site) if template = self.class.template_page(site) paginate(site, template) else Jekyll.logger.warn 'Pagination:', "Pagination is enabled, but I couldn't find " + 'an index.html page to use as the pagination template. Skipping pagination.' end 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> }
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fenton-jekyll-plugin/jb_jekyll_paging.rb', line 33 def paginate(site, page) all_posts = site.site_payload['site']['posts'].reject { |post| post['hidden'] } pages = Pager.calculate_pages(all_posts, site.config['page_size'].to_i) (1..pages).each do |num_page| pager = Pager.new(site, num_page, all_posts, pages) if num_page > 1 newpage = Jekyll::Page.new(site, site.source, page.dir, page.name) newpage.pager = pager newpage.dir = Pager.paginate_path(site, num_page) site.pages << newpage else page.pager = pager end end end |