Created
November 29, 2013 20:24
-
-
Save snrbrnjna/7711441 to your computer and use it in GitHub Desktop.
To exclude some configurable posts from Jekyll's default pagination on index.html pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jekyll | |
module Generators | |
class Pagination | |
# Monkey patch this method to exclude some cats and tags from all standard | |
# paginators | |
# | |
# For this to take effect, you have to define a ``exclude_home`` property in your _config.yml: | |
# | |
# exclude_home: | |
# categories: [notes] | |
# tags: [hidehome] | |
# | |
def paginate(site, page) | |
all_posts = _exclude_posts(site) | |
pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i) | |
(1..pages).each do |num_page| | |
pager = Pager.new(site, num_page, all_posts, pages) | |
if num_page > 1 | |
newpage = Page.new(site, site.source, page.dir, page.name) | |
newpage.pager = pager | |
newpage.dir = Pager.paginate_path(site, num_page) | |
site.pages << newpage | |
else | |
page.pager = pager | |
end | |
end | |
end | |
def _exclude_posts site | |
posts = site.site_payload['site']['posts'] | |
if (config=site.config['exclude_home']) | |
cats = config['categories']; tags = config['tags'] | |
posts.reject! do |post| | |
reject = false | |
if cats.is_a?(Array) | |
cats.each do |excat| | |
if post.categories.include?(excat) | |
reject = true | |
break | |
end | |
end | |
end | |
if !reject && tags.is_a?(Array) | |
tags.each do |extag| | |
if post.tags.include?(extag) | |
reject = true | |
break | |
end | |
end | |
end | |
reject | |
end | |
end | |
posts | |
end | |
end | |
end | |
end |
Never mind, I fixed it. Somehow my Jekyll version got all screwed up.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For some reason, the latest version of Jekyll is throwing this error when I try to generate my site:
When I trace the error I get this:
Any idea if I can fix this?