Class: Jekyll::Paginate::Categories::CategoryPagination
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::Paginate::Categories::CategoryPagination
- Defined in:
- lib/jekyll-paginate-categories.rb
Overview
Per-category pagination. Based on jekyll-paginate.
paginate_category_basepath: category base path - eg, /category/:name/ paginate_path: will be concatenated with paginate_category - eg /page/:num/ paginate_category_layout: The layout name of the category layout (default: categories.html)
Instance Method Summary collapse
-
#generate(site) ⇒ Object
Generate paginated pages if necessary.
-
#paginate_category(site, category) ⇒ Object
Do the blog’s posts pagination per category.
Instance Method Details
#generate(site) ⇒ Object
Generate paginated pages if necessary.
site - The Site.
Returns nothing.
25 26 27 28 29 30 31 |
# File 'lib/jekyll-paginate-categories.rb', line 25 def generate(site) if site.config['paginate_category_basepath'] for category in site.categories.keys paginate_category(site, category) end end end |
#paginate_category(site, category) ⇒ Object
Do the blog’s posts pagination per category. Renders the index.html file into paginated directories (see paginate_category_basepath and paginate_path config) for these categories, e.g.: /categories/my-category/page2/index.html, /categories/my-category/page3/index.html, etc.
site - The Site. category - The category to paginate.
Returns nothing.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jekyll-paginate-categories.rb', line 41 def paginate_category(site, category) # Retrieve posts from that specific category. all_posts = site.site_payload['site']['categories'][category] # Category base path category_path = site.config['paginate_category_basepath'] category_path = category_path.sub(':name', category.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')) # Count pages nb_pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i) # Create pages (1..nb_pages).each do |current_num_page| # Split posts into pages pager = Pager.new(site, current_num_page, all_posts, nb_pages) pager.update_paginate_paths(site, category_path) # Create new page, based on category layout newpage = CategoryPage.new(site, site.source, category) newpage.pager = pager newpage.dir = Pager.paginate_path_category(site, current_num_page, category_path) site.pages << newpage end end |