class Jekyll::Paginate::Simplecategory::Pagination
Public Instance Methods
generate(site)
click to toggle source
# File lib/jekyll-paginate-simplecategory.rb, line 11 def generate(site) if CategoryPager.pagination_enabled?(site) paginate(site) end end
paginate(site)
click to toggle source
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.
{“paginator” => { “page” => <Number>,
"per_page" => <Number>, "posts" => [<Post>], "total_posts" => <Number>, "total_pages" => <Number>, "previous_page" => <Number>, "next_page" => <Number> }}
# File lib/jekyll-paginate-simplecategory.rb, line 30 def paginate(site) if category_layout = site.config['category_layout'] template_name = File.basename(category_layout) template_dir = File.dirname(category_layout) template_dir = '/_layouts' if template_dir == '.' template_dir.prepend('/') unless template_dir.start_with? '/' else if template = template_page(site) template_name = template.name template_dir = template.dir 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 site.categories.each do |category, all_posts| all_posts = all_posts.reject { |p| p['hidden'] } pages = CategoryPager.calculate_pages(all_posts, site.config['paginate'].to_i) (1..pages).each do |num_page| paginate_path = CategoryPager.paginate_path(site, num_page, category) pager = CategoryPager.new(site, num_page, all_posts, pages, category) if page_title = site.config['category_page_title'] page_title = page_title.sub(':categories', category.capitalize) page_title = page_title.sub(':num', num_page.to_s) end site.pages << CategoryPage.new(site, site.source, paginate_path, 'index.html', template_dir, template_name, pager, page_title) end end end
template_page(site)
click to toggle source
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
# File lib/jekyll-paginate-simplecategory.rb, line 65 def template_page(site) site.pages.dup.select do |page| CategoryPager.pagination_candidate?(site.config, page) end.sort do |one, two| two.path.size <=> one.path.size end.first end