Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for excluding categories #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ paginate:
title_suffix: " - page :num" # Append to template's page title
category: '' # Paginate items in this category
categories: [] # Paginate items in any of these categories
exclude_category: '' # Exclude items in this category
exclude_categories: [] # Exclude items in any of those categories
tag: '' # Paginate items tagged with this tag
tags: [] # Paginate items tagged with any of these tags
```
Expand Down
8 changes: 8 additions & 0 deletions lib/octopress-paginate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def paginate(page)
page.data['paginate']['categories'] = Array(category)
end

if exclude_category = page.data['paginate']['exclude_category']
page.data['paginate']['exclude_categories'] = Array(exclude_category)
end

add_pages(page)
end

Expand Down Expand Up @@ -143,6 +147,10 @@ def collection(page)
collection = collection.reject{|p| (p.categories & categories).empty?}
end

if exclude_categories = page.data['paginate']['exclude_categories']
collection = collection.reject{|p| !(p.categories & exclude_categories).empty?}
end

if tags = page.data['paginate']['tags']
collection = collection.reject{|p| (p.tags & tags).empty?}
end
Expand Down