mirror of
https://github.com/kremalicious/blog.git
synced 2025-02-14 21:10:25 +01:00
lazy categories without pagination
This commit is contained in:
parent
765b5e5c49
commit
ae677a063f
@ -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
|
|
@ -9,10 +9,8 @@ category: design
|
|||||||
|
|
||||||
<h1 class="page-title icon icon-{{ page.category }}">{{ page.category }}</h1>
|
<h1 class="page-title icon icon-{{ page.category }}">{{ page.category }}</h1>
|
||||||
|
|
||||||
{% for post in paginator.posts %}
|
{% for post in site.categories.design %}
|
||||||
|
|
||||||
{% include articles.html %}
|
{% include articles.html %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
@ -9,10 +9,8 @@ category: goodies
|
|||||||
|
|
||||||
<h1 class="page-title icon icon-{{ page.category }}">{{ page.category }}</h1>
|
<h1 class="page-title icon icon-{{ page.category }}">{{ page.category }}</h1>
|
||||||
|
|
||||||
{% for post in paginator.posts %}
|
{% for post in site.categories.goodies %}
|
||||||
|
|
||||||
{% include articles.html %}
|
{% include articles.html %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
@ -8,10 +8,8 @@ category: personal
|
|||||||
|
|
||||||
<h1 class="page-title icon icon-{{ page.category }}">{{ page.category }}</h1>
|
<h1 class="page-title icon icon-{{ page.category }}">{{ page.category }}</h1>
|
||||||
|
|
||||||
{% for post in paginator.posts %}
|
{% for post in site.categories.personal %}
|
||||||
|
|
||||||
{% include articles.html %}
|
{% include articles.html %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
@ -8,10 +8,8 @@ category: photography
|
|||||||
|
|
||||||
<h1 class="page-title icon icon-{{ page.category }}">{{ page.category }}</h1>
|
<h1 class="page-title icon icon-{{ page.category }}">{{ page.category }}</h1>
|
||||||
|
|
||||||
{% for post in paginator.posts %}
|
{% for post in site.categories.photography %}
|
||||||
|
|
||||||
{% include articles.html %}
|
{% include articles.html %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
@ -12,10 +12,8 @@ category: photos
|
|||||||
<div class="masonry">
|
<div class="masonry">
|
||||||
<div class="grid-sizer"></div>
|
<div class="grid-sizer"></div>
|
||||||
|
|
||||||
{% for post in paginator.posts %}
|
{% for post in site.categories.photos %}
|
||||||
|
|
||||||
{% include articles.html %}
|
{% include articles.html %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user