From ae677a063ff7957f6594f56a13210bb1b4f59897 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sat, 9 Aug 2014 23:07:34 +0200 Subject: [PATCH] lazy categories without pagination --- _src/_plugins/cat_pagination.rb | 80 --------------------------------- _src/design/index.html | 4 +- _src/goodies/index.html | 4 +- _src/personal/index.html | 4 +- _src/photography/index.html | 4 +- _src/photos/index.html | 4 +- 6 files changed, 5 insertions(+), 95 deletions(-) delete mode 100644 _src/_plugins/cat_pagination.rb diff --git a/_src/_plugins/cat_pagination.rb b/_src/_plugins/cat_pagination.rb deleted file mode 100644 index af788f0f..00000000 --- a/_src/_plugins/cat_pagination.rb +++ /dev/null @@ -1,80 +0,0 @@ -# -# https://gist.github.com/runemadsen/6263974 -# -# modified -# - -module Jekyll - module Paginate - - class Pagination < Generator - def generate(site) - end - end - - class CategoryPages < Generator - - safe true - - def generate(site) - - site.pages.dup.each do |page| - paginate(site, page) if CategoryPager.pagination_enabled?(site.config, page) - end - - end - - def paginate(site, page) - - # sort categories by descending date of publish - category_posts = site.categories[page.data['category']].sort_by { |p| -p.date.to_f } - - # calculate total number of pages - pages = CategoryPager.calculate_pages(category_posts, site.config['paginate'].to_i) - - # iterate over the total number of pages and create a physical page for each - (1..pages).each do |num_page| - - # the CategoryPager handles the paging and category data - pager = CategoryPager.new(site, num_page, category_posts, page.data['category'], 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 - - end - - class CategoryPager < Pager - - attr_reader :category - - def self.pagination_enabled?(config, page) - page.name == 'index.html' && page.data.key?('category') && !config['paginate'].nil? - end - - # same as the base class, but includes the category value - def initialize(site, page, all_posts, category, num_pages = nil) - @category = category - super site, page, all_posts, num_pages - end - - # use the original to_liquid method, but add in category info - alias_method :original_to_liquid, :to_liquid - def to_liquid - x = original_to_liquid - x['category'] = @category - x - end - - end - - end -end \ No newline at end of file diff --git a/_src/design/index.html b/_src/design/index.html index 33e5fe70..86481199 100644 --- a/_src/design/index.html +++ b/_src/design/index.html @@ -9,10 +9,8 @@ category: design

{{ page.category }}

- {% for post in paginator.posts %} - + {% for post in site.categories.design %} {% include articles.html %} - {% endfor %} diff --git a/_src/goodies/index.html b/_src/goodies/index.html index 6f440f7d..23892ede 100644 --- a/_src/goodies/index.html +++ b/_src/goodies/index.html @@ -9,10 +9,8 @@ category: goodies

{{ page.category }}

- {% for post in paginator.posts %} - + {% for post in site.categories.goodies %} {% include articles.html %} - {% endfor %} diff --git a/_src/personal/index.html b/_src/personal/index.html index e38850e3..e7518620 100644 --- a/_src/personal/index.html +++ b/_src/personal/index.html @@ -8,10 +8,8 @@ category: personal

{{ page.category }}

- {% for post in paginator.posts %} - + {% for post in site.categories.personal %} {% include articles.html %} - {% endfor %} diff --git a/_src/photography/index.html b/_src/photography/index.html index 647e19ac..8efe0184 100644 --- a/_src/photography/index.html +++ b/_src/photography/index.html @@ -8,10 +8,8 @@ category: photography

{{ page.category }}

- {% for post in paginator.posts %} - + {% for post in site.categories.photography %} {% include articles.html %} - {% endfor %} diff --git a/_src/photos/index.html b/_src/photos/index.html index 1577bee7..4a4d6b32 100644 --- a/_src/photos/index.html +++ b/_src/photos/index.html @@ -12,10 +12,8 @@ category: photos
- {% for post in paginator.posts %} - + {% for post in site.categories.photos %} {% include articles.html %} - {% endfor %}