jekyll-paginate-simplecategory 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e454db7d9b8186e90b186d30d660ce2f3ecbfdd1
4
+ data.tar.gz: 68ca3397250de25afdd81f27c5a6080d61aa538b
5
+ SHA512:
6
+ metadata.gz: faa31784bc9dbaa4e50c622e24de5eb326354adcfaca67e7d493f92aecfc637620eb2495e9e5a19dc7fb3487205ce6066dadf5d9fd690bb4a0b212fa22d194d6
7
+ data.tar.gz: e8873e9cff056f3cf1b32ef4ce62c9c5534cbe125aa1a985d800f024be9009f7e85271d2ce7ce007aa9ac152b0fd1b49be82e84704cc8c737979945618773b39
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Santosh Kumar Gupta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Jekyll::Paginate::Simplecategory
2
+
3
+ Simple Pagination Generator for Jekyll Posts Categories
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'jekyll-paginate-simplecategory'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install jekyll-paginate-simplecategory
21
+
22
+
23
+ ## Usage
24
+
25
+ ### Config Example
26
+
27
+ Example of `_config.yml` file:
28
+
29
+ ```yaml
30
+ # Plugins
31
+ gems:
32
+ - jekyll-paginate
33
+ - jekyll-paginate-simplecategory
34
+
35
+ # Pagination
36
+ paginate: 5
37
+ paginate_path: "/blog/page:num"
38
+
39
+ category_paginate_path: "/blog/:categories/page:num"
40
+ ```
41
+
42
+ ### Customization
43
+
44
+ #### Layout
45
+
46
+ Simplecategory uses the default layout template set for pagination configured in the `paginate_path` parameter. To change the default layout add the `category_layout` parameter in `_config.yml` file:
47
+
48
+ ```yaml
49
+ # Pagination
50
+ category_layout: "category.html"
51
+ ```
52
+
53
+ Create the layout file `category.html` in `_layout` directory. If you are placing the layout file in any other directory than put the relative path of the file as below.
54
+
55
+ ```yaml
56
+ # Pagination
57
+ category_layout: "/my_layouts/category.html"
58
+ ```
59
+
60
+ #### Other
61
+
62
+ You can set a custom title for each pages by adding the `category_page_title` parameter in `_config.yml` file:
63
+
64
+ ```yaml
65
+ # Pagination
66
+ category_page_title: "My Blog - :categories - Page:num"
67
+ ```
68
+
69
+
70
+ ## Contributing
71
+
72
+ Feel free to report any bug and/or submit any improvement pull requests.
73
+
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
78
+
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll-paginate-simplecategory/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'jekyll-paginate-simplecategory'
8
+ s.version = Jekyll::Paginate::Simplecategory::VERSION
9
+ s.authors = ['Santosh Kumar Gupta']
10
+ s.email = ['santosh0705@gmail.com']
11
+ s.summary = 'Simple Pagination Generator for Jekyll Posts Categories'
12
+ s.description = 'Automatically Generate Pagination for Jekyll Posts Categories'
13
+ s.homepage = 'https://github.com/santosh0705/jekyll-paginate-simplecategory'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files -z`.split("\x0")
17
+ s.require_paths = ['lib']
18
+
19
+ s.add_development_dependency 'jekyll', '~> 2.0', '>=2.0'
20
+ s.add_development_dependency 'jekyll-paginate', '~> 1.1'
21
+ s.add_development_dependency 'rake', '~> 0'
22
+ end
@@ -0,0 +1,129 @@
1
+ require 'jekyll-paginate-simplecategory/version'
2
+
3
+ module Jekyll
4
+ module Paginate
5
+ module Simplecategory
6
+
7
+ class Pagination < Generator
8
+ safe true
9
+ priority :lowest
10
+
11
+ def generate(site)
12
+ if CategoryPager.pagination_enabled?(site)
13
+ paginate(site)
14
+ end
15
+ end
16
+
17
+ # Paginates the blog's posts. Renders the index.html file into paginated
18
+ # directories, e.g.: page2/index.html, page3/index.html, etc and adds more
19
+ # site-wide data.
20
+ #
21
+ # site - The Site.
22
+ #
23
+ # {"paginator" => { "page" => <Number>,
24
+ # "per_page" => <Number>,
25
+ # "posts" => [<Post>],
26
+ # "total_posts" => <Number>,
27
+ # "total_pages" => <Number>,
28
+ # "previous_page" => <Number>,
29
+ # "next_page" => <Number> }}
30
+ def paginate(site)
31
+ if category_layout = site.config['category_layout']
32
+ template_name = File.basename(category_layout)
33
+ template_dir = File.dirname(category_layout)
34
+ template_dir = '/_layouts' if template_dir == '.'
35
+ template_dir.prepend('/') unless template_dir.start_with? '/'
36
+ else
37
+ if template = template_page(site)
38
+ template_name = template.name
39
+ template_dir = template.dir
40
+ else
41
+ Jekyll.logger.warn "Pagination:", "Pagination is enabled, but I couldn't find " +
42
+ "an index.html page to use as the pagination template. Skipping pagination."
43
+ end
44
+ end
45
+ site.categories.each do |category, all_posts|
46
+ all_posts = all_posts.reject { |p| p['hidden'] }
47
+ pages = CategoryPager.calculate_pages(all_posts, site.config['paginate'].to_i)
48
+ (1..pages).each do |num_page|
49
+ paginate_path = CategoryPager.paginate_path(site, num_page, category)
50
+ pager = CategoryPager.new(site, num_page, all_posts, pages, category)
51
+ if page_title = site.config['category_page_title']
52
+ page_title = page_title.sub(':categories', category.capitalize)
53
+ page_title = page_title.sub(':num', num_page.to_s)
54
+ end
55
+ site.pages << CategoryPage.new(site, site.source, paginate_path, 'index.html', template_dir, template_name, pager, page_title)
56
+ end
57
+ end
58
+ end
59
+
60
+ # Find the Jekyll::Page which will act as the pager template
61
+ #
62
+ # site - the Jekyll::Site object
63
+ #
64
+ # Returns the Jekyll::Page which will act as the pager template
65
+ def template_page(site)
66
+ site.pages.dup.select do |page|
67
+ CategoryPager.pagination_candidate?(site.config, page)
68
+ end.sort do |one, two|
69
+ two.path.size <=> one.path.size
70
+ end.first
71
+ end
72
+ end
73
+
74
+ class CategoryPage < Page
75
+ def initialize(site, base, dir, name, template_dir, template_name, pager, page_title)
76
+ @site = site
77
+ @base = base
78
+ @dir = dir
79
+ @name = name
80
+ @pager = pager
81
+
82
+ self.process(@name)
83
+ self.read_yaml(File.join(base, template_dir), template_name)
84
+ self.data['title'] = page_title if page_title
85
+ end
86
+ end
87
+
88
+ class CategoryPager < Paginate::Pager
89
+ def initialize(site, page, all_posts, num_pages = nil, category)
90
+ @page = page
91
+ @per_page = site.config['paginate'].to_i
92
+ @total_pages = num_pages || CategoryPager.calculate_pages(all_posts, @per_page)
93
+
94
+ if @page > @total_pages
95
+ raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}"
96
+ end
97
+
98
+ init = (@page - 1) * @per_page
99
+ offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1)
100
+
101
+ @total_posts = all_posts.size
102
+ @posts = all_posts[init..offset]
103
+ @previous_page = @page != 1 ? @page - 1 : nil
104
+ @previous_page_path = CategoryPager.paginate_path(site, @previous_page, category)
105
+ @next_page = @page != @total_pages ? @page + 1 : nil
106
+ @next_page_path = CategoryPager.paginate_path(site, @next_page, category)
107
+ end
108
+
109
+ # Return the pagination path of the page
110
+ #
111
+ # site - the Jekyll::Site object
112
+ # num_page - the pagination page number
113
+ # category - the category name
114
+ #
115
+ # Returns the pagination path as a string
116
+ def self.paginate_path(site, num_page, category)
117
+ return nil if num_page.nil?
118
+ path = site.config['category_paginate_path'] || '/blog/:categories/page:num'
119
+ path = path.sub(':categories', category)
120
+ path = path.sub(':num', num_page.to_s)
121
+ path.prepend('/') unless path.start_with? '/'
122
+ path_first = File.dirname(path)
123
+ num_page <= 1 ? path_first : path
124
+ end
125
+ end
126
+
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,7 @@
1
+ module Jekyll
2
+ module Paginate
3
+ module Simplecategory
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-paginate-simplecategory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Santosh Kumar Gupta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: jekyll-paginate
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ description: Automatically Generate Pagination for Jekyll Posts Categories
62
+ email:
63
+ - santosh0705@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - LICENSE
70
+ - README.md
71
+ - jekyll-paginate-simplecategory.gemspec
72
+ - lib/jekyll-paginate-simplecategory.rb
73
+ - lib/jekyll-paginate-simplecategory/version.rb
74
+ homepage: https://github.com/santosh0705/jekyll-paginate-simplecategory
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Simple Pagination Generator for Jekyll Posts Categories
98
+ test_files: []