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

Jekyll3 #24

Open
wants to merge 4 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: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in octopress-paginate.gemspec
gemspec
16 changes: 10 additions & 6 deletions lib/octopress-paginate.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require "octopress-hooks"
require "octopress-paginate/version"
require "octopress-paginate/hooks"

begin
require "octopress-debugger"
rescue LoadError; end


module Octopress
module Paginate
extend self
Expand Down Expand Up @@ -133,18 +137,18 @@ def collection(page)
if defined?(Octopress::Multilingual) && page.lang
page.site.posts_by_language(page.lang)
else
page.site.posts.reverse
page.site.posts.docs.reverse
end
else
page.site.collections[page['paginate']['collection']].docs
end

if categories = page.data['paginate']['categories']
collection = collection.reject{|p| (p.categories & categories).empty?}
collection = collection.reject{|p| (p.data['categories'] & categories).empty?}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XhmikosR I think these p.data changes are still required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be because I don't use categories so that code isn't run at all?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make sense, yes.

end

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

collection
Expand All @@ -153,7 +157,7 @@ def collection(page)
def page_payload(payload, page)
config = page.data['paginate']
collection = collection(page)
{ 'paginator' => {
{
"#{config['collection']}" => items(payload, collection),
"page" => config['page_num'],
"per_page" => config['per_page'],
Expand All @@ -164,7 +168,7 @@ def page_payload(payload, page)
'previous_page_path' => config['previous_page_path'],
'next_page' => config['next_page'],
'next_page_path' => config['next_page_path']
}}
}
end

def items(payload, collection)
Expand Down
32 changes: 23 additions & 9 deletions lib/octopress-paginate/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
module Octopress
module Paginate
class SiteHook < Hooks::Site
priority :low

def post_read(site)
if defined?(Jekyll::Hooks)
Jekyll::Hooks.register :site, :post_read, priority: :low do |site|
site.pages.select {|p| p.data['paginate'] }.each do |page|
Octopress::Paginate.paginate(page)
end
end
end

class PageHook < Hooks::Page
def merge_payload(payload, page)
Jekyll::Hooks.register :pages, :pre_render do |page, payload|
if page.data['paginate']
Octopress::Paginate.page_payload(payload, page)
payload['paginator'] = Octopress::Paginate.page_payload(payload, page)
end
end
else
require 'octopress-hooks'
class SiteHook < Hooks::Site
priority :low

def post_read(site)
site.pages.select {|p| p.data['paginate'] }.each do |page|
Octopress::Paginate.paginate(page)
end
end
end

class PageHook < Hooks::Page
def merge_payload(payload, page)
if page.data['paginate']
payload['paginator'] = Octopress::Paginate.page_payload(payload, page)
end
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions octopress-paginate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_runtime_dependency "octopress-hooks"
#spec.add_runtime_dependency "octopress-hooks"
spec.add_runtime_dependency "jekyll"

spec.add_development_dependency "clash"
spec.add_development_dependency "bundler", "~> 1.7"
Expand All @@ -26,6 +27,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "octopress"

if RUBY_VERSION >= "2"
spec.add_development_dependency "pry-byebug"
spec.add_development_dependency "octopress-debugger"
end
end
Binary file added test/collection/.jekyll-metadata
Binary file not shown.
Binary file added test/filter-category/.jekyll-metadata
Binary file not shown.
Binary file added test/limit/.jekyll-metadata
Binary file not shown.
Binary file added test/multilingual/.jekyll-metadata
Binary file not shown.
Binary file added test/no-limit/.jekyll-metadata
Binary file not shown.
Binary file added test/site-config/.jekyll-metadata
Binary file not shown.
Binary file added test/standard/.jekyll-metadata
Binary file not shown.