class Jekyll::Paginate::Simplecategory::CategoryPager
Public Class Methods
new(site, page, all_posts, num_pages = nil, category)
click to toggle source
# File lib/jekyll-paginate-simplecategory.rb, line 89 def initialize(site, page, all_posts, num_pages = nil, category) @page = page @per_page = site.config['paginate'].to_i @total_pages = num_pages || CategoryPager.calculate_pages(all_posts, @per_page) if @page > @total_pages raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}" end init = (@page - 1) * @per_page offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1) @total_posts = all_posts.size @posts = all_posts[init..offset] @previous_page = @page != 1 ? @page - 1 : nil @previous_page_path = CategoryPager.paginate_path(site, @previous_page, category) @next_page = @page != @total_pages ? @page + 1 : nil @next_page_path = CategoryPager.paginate_path(site, @next_page, category) end
paginate_path(site, num_page, category)
click to toggle source
Return the pagination path of the page
site - the Jekyll::Site object num_page - the pagination page number category - the category name
Returns the pagination path as a string
# File lib/jekyll-paginate-simplecategory.rb, line 116 def self.paginate_path(site, num_page, category) return nil if num_page.nil? path = site.config['category_paginate_path'] || '/blog/:categories/page:num' path = path.sub(':categories', category) path = path.sub(':num', num_page.to_s) path.prepend('/') unless path.start_with? '/' path_first = File.dirname(path) num_page <= 1 ? path_first : path end