jekyll-category-pages 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +184 -0
- data/lib/jekyll-category-pages.rb +15 -0
- data/lib/jekyll-category-pages/version.rb +19 -0
- data/lib/jekyll/category_pages.rb +291 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 729a4240777ec89a28d3fe0b835dd735e9c14352
|
4
|
+
data.tar.gz: 96bbf4220a73525d2433b9e5646450ad9fccec14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e6733ba05be842bf0ebfa01e54345eb12802e467d782e5597c7ee4ffb0a356dbf4b6a2452d78117c838472996e62227bde4e2ae82a3ec23ae5a1219b8e169421
|
7
|
+
data.tar.gz: 075ad1385dac2cfcca6f10852a6fa0795f2fc378d00b20753eef1e4ec5fa9223cfb50c2ee3501d68b482fe5b93417b81372feff071e054d4a3d1bc5629d529e7
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) since 2017 by Tamanguu GmbH & Co KG
|
4
|
+
Written by Dr. Wolfram Schroers <Wolfram.Schroers -at- tamanguu.com>
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
# jekyll-category-pages
|
2
|
+
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/jekyll-category-pages.svg)](https://rubygems.org/gems/jekyll-category-pages)
|
4
|
+
[![Build Status](https://travis-ci.org/field-theory/jekyll-category-pages.png?branch=master)](https://travis-ci.org/field-theory/jekyll-category-pages)
|
5
|
+
|
6
|
+
This plugin adds category index pages with and without pagination.
|
7
|
+
Benefits are:
|
8
|
+
* Easy to setup and use, fully compatible with the default [pagination
|
9
|
+
plugin](https://github.com/jekyll/jekyll-paginate) (also cf. the
|
10
|
+
[official documenation](https://jekyllrb.com/docs/pagination/)).
|
11
|
+
* Supports category keys with spaces and other special characters.
|
12
|
+
* Complete documentation and a usage example.
|
13
|
+
* Test coverage of key features.
|
14
|
+
* Category index pages are generated based on a customizable template.
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Assign one or more categories in the YAML front matter of each page:
|
19
|
+
```yaml
|
20
|
+
categories: [Category Pages Plugin, jekyll]
|
21
|
+
```
|
22
|
+
Generate the site and the category pages are generated:
|
23
|
+
```
|
24
|
+
_site/category/
|
25
|
+
├── Category%20Pages%20Plugin/
|
26
|
+
│ └── index.html
|
27
|
+
├── %E5%A5%BD%E7%9A%84%E4%B8%BB%E6%84%8F/
|
28
|
+
│ └── index.html
|
29
|
+
└── jekyll/
|
30
|
+
├── index.html
|
31
|
+
├── page2.html
|
32
|
+
└── page3.html
|
33
|
+
```
|
34
|
+
In this example there are three paginated index pages for the `jekyll`
|
35
|
+
category (apparently, there are many posts for this category), a
|
36
|
+
single index page for the `好的主意` category and another single index
|
37
|
+
page for the `Category Pages Plugin` category.
|
38
|
+
|
39
|
+
Note that the YAML `categories` entry should always use brackets `[]`
|
40
|
+
to make it explicit that it is an array!
|
41
|
+
|
42
|
+
You can find this example in the `example` directory of the [git
|
43
|
+
repository](https://github.com/field-theory/jekyll-category-pages).
|
44
|
+
|
45
|
+
### The example project
|
46
|
+
|
47
|
+
The `example` directory contains a basic example project that
|
48
|
+
demonstrates the different use cases. In order to run Jekyll on these
|
49
|
+
examples use:
|
50
|
+
```shell
|
51
|
+
bundle install
|
52
|
+
bundle exec rake example
|
53
|
+
```
|
54
|
+
The result is put in `example/_site`.
|
55
|
+
|
56
|
+
## Installation and setup
|
57
|
+
|
58
|
+
Installation is straightforward (like other plugins):
|
59
|
+
1. Add the plugin to the site's `Gemfile` and configuration file:
|
60
|
+
```ruby
|
61
|
+
group :jekyll_plugins do
|
62
|
+
gem "jekyll-category-pages"
|
63
|
+
end
|
64
|
+
```
|
65
|
+
and run `bundle install`. If you want to use pagination, also
|
66
|
+
install the `jekyll-paginate` gem:
|
67
|
+
```ruby
|
68
|
+
group :jekyll_plugins do
|
69
|
+
gem "jekyll-paginate"
|
70
|
+
gem "jekyll-category-pages"
|
71
|
+
end
|
72
|
+
```
|
73
|
+
2. Add the plugin to your site's `_config.yml`:
|
74
|
+
```ruby
|
75
|
+
plugins:
|
76
|
+
- jekyll-category-pages
|
77
|
+
```
|
78
|
+
3. Configure any other options you need (see below).
|
79
|
+
4. Add template for category pages (see below).
|
80
|
+
5. Set appropriate `categories` tags on each blog post YAML front
|
81
|
+
matter.
|
82
|
+
|
83
|
+
### Configuration
|
84
|
+
|
85
|
+
The following options can be set in the Jekyll configuration file
|
86
|
+
`_config.yml`:
|
87
|
+
* `category_path`: Root directory for category index pages. Defaults
|
88
|
+
to `category` if unset.
|
89
|
+
In the example this places the index file for category `jekyll` at
|
90
|
+
`example/_site/category/jekyll/index.html`.
|
91
|
+
* `category_layout`: Basic category index template. Defaults to
|
92
|
+
`category_index.html`. The layout **must** reside in the standard
|
93
|
+
`_layouts` directory.
|
94
|
+
In the example the layout is in
|
95
|
+
`example/_layouts/category_index.html`.
|
96
|
+
* `paginate`: (Maximum) number of posts on each category index
|
97
|
+
page. This is the same for the regular (front page) pagination. If
|
98
|
+
absent, pagination is turned off and only single index pages are
|
99
|
+
generated.
|
100
|
+
In the example `paginate` is set to 2.
|
101
|
+
|
102
|
+
### Template for category pages
|
103
|
+
|
104
|
+
The template for a category index page must be placed in the site's
|
105
|
+
`_layouts` directory. The attribute `category` indicates the current
|
106
|
+
category for which the page is generated. The page title also defaults
|
107
|
+
to the current category. The other attributes are similar to the
|
108
|
+
default Jekyll pagination plugin.
|
109
|
+
|
110
|
+
If no pagination is enabled the following attributes are available:
|
111
|
+
|
112
|
+
| Attribute | Description |
|
113
|
+
| ------------- | ----------------------------------------- |
|
114
|
+
| `category` | Current page category |
|
115
|
+
| `posts` | List of posts in current category |
|
116
|
+
| `total_posts` | Total number of posts in current category |
|
117
|
+
|
118
|
+
If pagination is enabled (i.e., if setting `site.paginate` globally in
|
119
|
+
`_config.yml`) then a `paginator` attribute is available which returns
|
120
|
+
an object with the following attributes:
|
121
|
+
|
122
|
+
| Attribute | Description |
|
123
|
+
| -------------------- | -------------------------------------------------------------------------------- |
|
124
|
+
| `page` | Current page number |
|
125
|
+
| `per_page` | Number of posts per page |
|
126
|
+
| `posts` | List of posts on the current page |
|
127
|
+
| `total_posts` | Total number of posts in current category |
|
128
|
+
| `total_pages` | Total number of pagination pages for the current category |
|
129
|
+
| `previous_page` | Page number of the previous pagination page, or `nil` if no previous page exists |
|
130
|
+
| `previous_page_path` | Path of previous pagination page, or `''` if no previous page exists |
|
131
|
+
| `next_page` | Page number of the next pagination page, or `nil` if no subsequent page exists |
|
132
|
+
| `next_page_path` | Path of next pagination page, or `''` if no subsequent page exists |
|
133
|
+
|
134
|
+
An example can be found in `example/_layouts/category_index.html`
|
135
|
+
which demonstrates the various attributes and their use.
|
136
|
+
|
137
|
+
### Category listing
|
138
|
+
|
139
|
+
A category overview with a full listing of all categories can be
|
140
|
+
created as follows:
|
141
|
+
```html
|
142
|
+
<ul>
|
143
|
+
{% for category in site.categories %}
|
144
|
+
<li><a href="{{ site.url }}/category/{{ category | first | url_encode }}/index.html">{{ category | first }}</a></li>
|
145
|
+
{% endfor %}
|
146
|
+
</ul>
|
147
|
+
```
|
148
|
+
Note that the category page paths are URL-encoded when generated by
|
149
|
+
this plugin. Thus, you have to use `url_encode` when linking to each
|
150
|
+
category. This saves you from problems with spaces or other special
|
151
|
+
characters in category names.
|
152
|
+
|
153
|
+
An example listing can be found in `example/index.html` which
|
154
|
+
shows a full listing of categories with corresponding links.
|
155
|
+
|
156
|
+
## Development
|
157
|
+
|
158
|
+
This project contains a `Rakefile` that supports the following
|
159
|
+
tasks:
|
160
|
+
* `build`: Runs all tests and builds the resulting gem file.
|
161
|
+
* `test`: Run all tests.
|
162
|
+
* `example`: Run Jekyll for the example project.
|
163
|
+
* `clean`: Clean up all transient files.
|
164
|
+
|
165
|
+
To run all test cases use:
|
166
|
+
```shell
|
167
|
+
bundle exec rake test
|
168
|
+
```
|
169
|
+
The tests run different Jekyll configurations and produce output files
|
170
|
+
that can be read by Ruby. These are then evaluted and validated using
|
171
|
+
[Ruby RSpec](http://rspec.info).
|
172
|
+
|
173
|
+
To build the gem use:
|
174
|
+
```shell
|
175
|
+
bundle exec rake build
|
176
|
+
```
|
177
|
+
The result is put in the current directory after all tests have been
|
178
|
+
run.
|
179
|
+
|
180
|
+
## License
|
181
|
+
|
182
|
+
The gem is available as open source under the terms of the [MIT
|
183
|
+
License](https://github.com/field-theory/jekyll-category-pages/blob/master/LICENSE).
|
184
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Copyright: Since 2017 Tamanguu GmbH & Co KG - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
#
|
6
|
+
# category_pages
|
7
|
+
# Add category index pages with and without pagination.
|
8
|
+
#
|
9
|
+
# (c) since 2017 by Tamanguu GmbH & Co KG
|
10
|
+
# Written by Dr. Wolfram Schroers <Wolfram.Schroers -at- tamanguu.com>
|
11
|
+
#
|
12
|
+
# See the accompanying file LICENSE for licensing conditions.
|
13
|
+
#
|
14
|
+
|
15
|
+
require "jekyll/category_pages"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Copyright: Since 2017 Tamanguu GmbH & Co KG - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
#
|
6
|
+
# jekyll-category-pages
|
7
|
+
# Add category index pages with and without pagination.
|
8
|
+
#
|
9
|
+
# (c) since 2017 by Tamanguu GmbH & Co KG
|
10
|
+
# Written by Dr. Wolfram Schroers <Wolfram.Schroers -at- tamanguu.com>
|
11
|
+
#
|
12
|
+
# See the accompanying file LICENSE for licensing conditions.
|
13
|
+
#
|
14
|
+
|
15
|
+
module Jekyll
|
16
|
+
module CategoryPages
|
17
|
+
VERSION = "1.0.0".freeze
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,291 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Encoding: utf-8
|
3
|
+
|
4
|
+
#
|
5
|
+
# category_pages
|
6
|
+
# Add category index pages with and without pagination.
|
7
|
+
#
|
8
|
+
# (c) since 2017 by Tamanguu GmbH & Co KG
|
9
|
+
# Written by Dr. Wolfram Schroers <Wolfram.Schroers -at- tamanguu.com>
|
10
|
+
#
|
11
|
+
# Copyright: Since 2017 Tamanguu GmbH & Co KG - MIT License
|
12
|
+
# See the accompanying file LICENSE for licensing conditions.
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'jekyll'
|
16
|
+
|
17
|
+
module Jekyll
|
18
|
+
module CategoryPages
|
19
|
+
INDEXFILE = 'index.html'
|
20
|
+
|
21
|
+
# Custom generator for generating all index pages based on a supplied layout.
|
22
|
+
#
|
23
|
+
# Note that this generator uses a layout instead of a regular page template, since
|
24
|
+
# it will generate a set of new pages, not merely variations of a single page like
|
25
|
+
# the blog index Paginator does.
|
26
|
+
class Pagination < Generator
|
27
|
+
# This generator is safe from arbitrary code execution.
|
28
|
+
safe true
|
29
|
+
priority :lowest
|
30
|
+
|
31
|
+
# Generate paginated category pages if necessary.
|
32
|
+
#
|
33
|
+
# site - The Site object.
|
34
|
+
def generate(site)
|
35
|
+
category_base_path = site.config['category_path'] || 'category'
|
36
|
+
category_layout_path = File.join('_layouts/', site.config['category_layout'] || 'category_index.html')
|
37
|
+
|
38
|
+
if Paginate::Pager.pagination_enabled?(site)
|
39
|
+
# Generate paginated category pages
|
40
|
+
generate_paginated_categories(site, category_base_path, category_layout_path)
|
41
|
+
else
|
42
|
+
# Generate category pages without pagination
|
43
|
+
generate_categories(site, category_base_path, category_layout_path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Sort the list of categories and remove duplicates.
|
48
|
+
#
|
49
|
+
# site - The Site object.
|
50
|
+
#
|
51
|
+
# Returns an array of strings containing the site's categories.
|
52
|
+
def sorted_categories(site)
|
53
|
+
categories = []
|
54
|
+
site.categories.each_pair do |category, pages|
|
55
|
+
categories.push(category)
|
56
|
+
end
|
57
|
+
categories.sort!.uniq!
|
58
|
+
return categories
|
59
|
+
end
|
60
|
+
|
61
|
+
# Generate the paginated category pages.
|
62
|
+
#
|
63
|
+
# site - The Site object.
|
64
|
+
# category_base_path - String with the base path to the category index pages.
|
65
|
+
# category_layout - The name of the basic category layout page.
|
66
|
+
def generate_paginated_categories(site, category_base_path, category_layout)
|
67
|
+
categories = sorted_categories site
|
68
|
+
|
69
|
+
# Generate the pages
|
70
|
+
for category in categories
|
71
|
+
posts_in_category = site.categories[category]
|
72
|
+
category_path = File.join(category_base_path, CGI.escape(category))
|
73
|
+
per_page = site.config['paginate']
|
74
|
+
|
75
|
+
page_number = CategoryPager.calculate_pages(posts_in_category, per_page)
|
76
|
+
page_paths = []
|
77
|
+
category_pages = []
|
78
|
+
(1..page_number).each do |current_page|
|
79
|
+
# Collect all paths in the first pass and generate the basic page templates.
|
80
|
+
page_name = current_page == 1 ? INDEXFILE : "page#{current_page}.html"
|
81
|
+
page_paths.push page_name
|
82
|
+
new_page = CategoryIndexPage.new(site, category_path, page_name, category, category_layout, posts_in_category, true)
|
83
|
+
category_pages.push new_page
|
84
|
+
end
|
85
|
+
|
86
|
+
(1..page_number).each do |current_page|
|
87
|
+
# Generate the paginator content in the second pass.
|
88
|
+
previous_link = current_page == 1 ? nil : page_paths[current_page - 2]
|
89
|
+
next_link = current_page == page_number ? nil : page_paths[current_page]
|
90
|
+
previous_page = current_page == 1 ? nil : (current_page - 1)
|
91
|
+
next_page = current_page == page_number ? nil : (current_page + 1)
|
92
|
+
category_pages[current_page - 1].add_paginator_relations(current_page, per_page, page_number,
|
93
|
+
previous_link, next_link, previous_page, next_page)
|
94
|
+
end
|
95
|
+
|
96
|
+
for page in category_pages
|
97
|
+
# Finally, add the new pages to the site in the third pass.
|
98
|
+
site.pages << page
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
Jekyll.logger.debug("Paginated categories", "Processed " + categories.size.to_s + " paginated category index pages")
|
103
|
+
end
|
104
|
+
|
105
|
+
# Generate the non-paginated category pages.
|
106
|
+
#
|
107
|
+
# site - The Site object.
|
108
|
+
# category_base_path - String with the base path to the category index pages.
|
109
|
+
# category_layout - The name of the basic category layout page.
|
110
|
+
def generate_categories(site, category_base_path, category_layout)
|
111
|
+
categories = sorted_categories site
|
112
|
+
|
113
|
+
# Generate the pages
|
114
|
+
for category in categories
|
115
|
+
posts_in_category = site.categories[category]
|
116
|
+
category_path = File.join(category_base_path, CGI.escape(category))
|
117
|
+
|
118
|
+
site.pages << CategoryIndexPage.new(site, category_path, INDEXFILE, category, category_layout, posts_in_category, false)
|
119
|
+
end
|
120
|
+
|
121
|
+
Jekyll.logger.debug("Categories", "Processed " + categories.size.to_s + " category index pages")
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Auto-generated page for a category index.
|
128
|
+
#
|
129
|
+
# When pagination is enabled, contains a CategoryPager object as paginator. The posts in the
|
130
|
+
# category are always available as posts, the total number of those is always total_posts.
|
131
|
+
class CategoryIndexPage < Page
|
132
|
+
# Attributes for Liquid templates.
|
133
|
+
ATTRIBUTES_FOR_LIQUID = %w(
|
134
|
+
category
|
135
|
+
paginator
|
136
|
+
posts
|
137
|
+
total_posts
|
138
|
+
content
|
139
|
+
dir
|
140
|
+
name
|
141
|
+
path
|
142
|
+
url
|
143
|
+
)
|
144
|
+
|
145
|
+
# Initialize a new category index page.
|
146
|
+
#
|
147
|
+
# site - The Site object.
|
148
|
+
# dir - Base directory for all category pages.
|
149
|
+
# page_name - Name of this category page (either 'index.html' or 'page#.html').
|
150
|
+
# category - Current category as a String.
|
151
|
+
# category_layout - Name of the category index page layout (must reside in the '_layouts' directory).
|
152
|
+
# posts_in_category - Array with full list of Posts in the current category.
|
153
|
+
# use_paginator - Whether a CategoryPager object shall be instantiated as 'paginator'.
|
154
|
+
def initialize(site, dir, page_name, category, category_layout, posts_in_category, use_paginator)
|
155
|
+
@site = site
|
156
|
+
@base = site.source
|
157
|
+
super(@site, @base, '', category_layout)
|
158
|
+
@dir = dir
|
159
|
+
@name = page_name
|
160
|
+
|
161
|
+
self.process @name
|
162
|
+
|
163
|
+
@category = category
|
164
|
+
@posts_in_category = posts_in_category
|
165
|
+
@my_paginator = nil
|
166
|
+
|
167
|
+
self.read_yaml(@base, category_layout)
|
168
|
+
self.data.merge!('title' => category)
|
169
|
+
if use_paginator
|
170
|
+
@my_paginator = CategoryPager.new
|
171
|
+
self.data.merge!('paginator' => @my_paginator)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# Add relations of this page to other pages handled by a CategoryPager.
|
176
|
+
#
|
177
|
+
# Note that this method SHALL NOT be called if the category pages are instantiated without pagination.
|
178
|
+
# This method SHALL be called if the category pages are instantiated with pagination.
|
179
|
+
#
|
180
|
+
# page - Current page number.
|
181
|
+
# per_page - Posts per page.
|
182
|
+
# total_pages - Total number of pages.
|
183
|
+
# previous_page - Number of previous page or nil.
|
184
|
+
# next_page - Number of next page or nil.
|
185
|
+
# previous_page_path - String with path to previous page or nil.
|
186
|
+
# next_page_path - String with path to next page or nil.
|
187
|
+
def add_paginator_relations(page, per_page, total_pages, previous_page_path, next_page_path, previous_page, next_page)
|
188
|
+
if @my_paginator
|
189
|
+
@my_paginator.add_relations(page, per_page, total_pages,
|
190
|
+
previous_page, next_page, previous_page_path, next_page_path)
|
191
|
+
@my_paginator.add_posts(page, per_page, @posts_in_category)
|
192
|
+
else
|
193
|
+
Jekyll.logger.warn("Categories", "add_relations does nothing since the category page has been initialized without pagination")
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
# Get the category name this index page refers to
|
198
|
+
#
|
199
|
+
# Returns a string.
|
200
|
+
def category
|
201
|
+
@category
|
202
|
+
end
|
203
|
+
|
204
|
+
# Get the paginator object describing the current index page.
|
205
|
+
#
|
206
|
+
# Returns a CategoryPager object or nil.
|
207
|
+
def paginator
|
208
|
+
@my_paginator
|
209
|
+
end
|
210
|
+
|
211
|
+
# Get all Posts in this category.
|
212
|
+
#
|
213
|
+
# Returns an Array of Posts.
|
214
|
+
def posts
|
215
|
+
@posts_in_category
|
216
|
+
end
|
217
|
+
|
218
|
+
# Get the number of posts in this category.
|
219
|
+
#
|
220
|
+
# Returns an Integer number of posts.
|
221
|
+
def total_posts
|
222
|
+
@posts_in_category.size
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# Handle pagination of category index pages.
|
227
|
+
class CategoryPager
|
228
|
+
attr_reader :page, :per_page, :posts, :total_posts, :total_pages,
|
229
|
+
:previous_page, :previous_page_path, :next_page, :next_page_path
|
230
|
+
|
231
|
+
# Static: Calculate the number of pages.
|
232
|
+
#
|
233
|
+
# all_posts - The Array of all Posts.
|
234
|
+
# per_page - The Integer of entries per page.
|
235
|
+
#
|
236
|
+
# Returns the Integer number of pages.
|
237
|
+
def self.calculate_pages(all_posts, per_page)
|
238
|
+
(all_posts.size.to_f / per_page.to_i).ceil
|
239
|
+
end
|
240
|
+
|
241
|
+
# Add numeric relationships of this page to other pages.
|
242
|
+
#
|
243
|
+
# page - Current page number.
|
244
|
+
# per_page - Posts per page.
|
245
|
+
# total_pages - Total number of pages.
|
246
|
+
# previous_page - Number of previous page or nil.
|
247
|
+
# next_page - Number of next page or nil.
|
248
|
+
# previous_page_path - String with path to previous page or nil.
|
249
|
+
# next_page_path - String with path to next page or nil.
|
250
|
+
def add_relations(page, per_page, total_pages, previous_page, next_page, previous_page_path, next_page_path)
|
251
|
+
@page = page
|
252
|
+
@per_page = per_page
|
253
|
+
@total_pages = total_pages
|
254
|
+
@previous_page = previous_page
|
255
|
+
@next_page = next_page
|
256
|
+
@previous_page_path = previous_page_path
|
257
|
+
@next_page_path = next_page_path
|
258
|
+
end
|
259
|
+
|
260
|
+
# Add page-specific post data.
|
261
|
+
#
|
262
|
+
# page - Current page number.
|
263
|
+
# per_page - Posts per page.
|
264
|
+
# posts_in_category - Array with full list of Posts in the current category.
|
265
|
+
def add_posts(page, per_page, posts_in_category)
|
266
|
+
total_posts = posts_in_category.size
|
267
|
+
init = (page - 1) * per_page
|
268
|
+
offset = (init + per_page - 1) >= total_posts ? total_posts : (init + per_page - 1)
|
269
|
+
|
270
|
+
@total_posts = total_posts
|
271
|
+
@posts = posts_in_category[init..offset]
|
272
|
+
end
|
273
|
+
|
274
|
+
# Convert this CategoryPager's data to a Hash suitable for use by Liquid.
|
275
|
+
#
|
276
|
+
# Returns the Hash representation of this CategoryPager.
|
277
|
+
def to_liquid
|
278
|
+
{
|
279
|
+
'page' => page,
|
280
|
+
'per_page' => per_page,
|
281
|
+
'posts' => posts,
|
282
|
+
'total_posts' => total_posts,
|
283
|
+
'total_pages' => total_pages,
|
284
|
+
'previous_page' => previous_page,
|
285
|
+
'previous_page_path' => previous_page_path,
|
286
|
+
'next_page' => next_page,
|
287
|
+
'next_page_path' => next_page_path
|
288
|
+
}
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-category-pages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dr. Wolfram Schroers
|
8
|
+
- Tamanguu GmbH & Co KG
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-12-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jekyll
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.5'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.5'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: jekyll-paginate
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.1'
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - "~>"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '1.1'
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.0
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
description: |
|
63
|
+
This plugin is for all authors that tag their pages using categories. It generates
|
64
|
+
category overview pages with a custom layout. Optionally, it also adds proper
|
65
|
+
pagination for these pages.
|
66
|
+
|
67
|
+
Please refer to the README.md file on the project homepage at
|
68
|
+
https://github.com/field-theory/jekyll-category-pages
|
69
|
+
email: Wolfram.Schroers@tamanguu.com
|
70
|
+
executables: []
|
71
|
+
extensions: []
|
72
|
+
extra_rdoc_files: []
|
73
|
+
files:
|
74
|
+
- LICENSE
|
75
|
+
- README.md
|
76
|
+
- lib/jekyll-category-pages.rb
|
77
|
+
- lib/jekyll-category-pages/version.rb
|
78
|
+
- lib/jekyll/category_pages.rb
|
79
|
+
homepage: https://github.com/field-theory/jekyll-category-pages
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.6.10
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Add category index pages with and without pagination.
|
103
|
+
test_files: []
|