jekyll-paginate-data 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87dfb180279b84e603e0f6bdef8c3e50eb801311286e5093cfb322f1283d66b6
4
+ data.tar.gz: c8fd3b62f5f16b55f3b4fa2a7bf2eda78bace0ef380d4aa75c970af031c4226a
5
+ SHA512:
6
+ metadata.gz: 269b0b9d213588a58179b4c669813695ea41060d33f1da42c23858fa67b69018e6df2eba20d1968e668b044584b95b998e4c191093ae00f0f0b7016ca6444683
7
+ data.tar.gz: c4546dfbe61689d9fd2614196b12ee1ccf84b6ae3a2e67503e87456be7fb95f228d84de15cb74b4e68d3dbf366fcb8819232774181fb4f2c4333a034dedc1216
@@ -0,0 +1,104 @@
1
+ name: Continuous Integration
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ j4:
13
+ if: "!contains(github.event.commits[0].message, '[ci skip]')"
14
+ name: "Jekyll ${{ matrix.jekyll_version }} (Ruby ${{ matrix.ruby_version }})"
15
+ runs-on: 'ubuntu-latest'
16
+ env:
17
+ JEKYLL_VERSION: ${{ matrix.jekyll_version }}
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ ruby_version:
22
+ - 2.5
23
+ - 2.7
24
+ - 3.0
25
+ jekyll_version:
26
+ - "~> 3.0"
27
+ - "~> 4.0"
28
+ steps:
29
+ - uses: actions/checkout@v2
30
+ with:
31
+ fetch-depth: 5
32
+ - name: "Set up Ruby ${{ matrix.ruby_version }}"
33
+ uses: ruby/setup-ruby@v1
34
+ with:
35
+ ruby-version: ${{ matrix.ruby_version }}
36
+ bundler-cache: true
37
+ - name: Execute tests
38
+ run: bundle exec rspec
39
+ j3:
40
+ if: "!contains(github.event.commits[0].message, '[ci skip]')"
41
+ name: "Jekyll ${{ matrix.jekyll_version }} (Ruby ${{ matrix.ruby_version }})"
42
+ runs-on: 'ubuntu-latest'
43
+ env:
44
+ JEKYLL_VERSION: ${{ matrix.jekyll_version }}
45
+ strategy:
46
+ fail-fast: false
47
+ matrix:
48
+ ruby_version:
49
+ - 2.5
50
+ jekyll_version:
51
+ - "~> 3.9"
52
+ steps:
53
+ - uses: actions/checkout@v2
54
+ with:
55
+ fetch-depth: 5
56
+ - name: "Set up Ruby ${{ matrix.ruby_version }}"
57
+ uses: ruby/setup-ruby@v1
58
+ with:
59
+ ruby-version: ${{ matrix.ruby_version }}
60
+ bundler-cache: true
61
+ - name: Execute tests
62
+ run: 'bundle exec rspec && true'
63
+
64
+ style_check:
65
+ if: "!contains(github.event.commits[0].message, '[ci skip]')"
66
+ name: "Code Style Check (Ruby ${{ matrix.ruby_version }})"
67
+ runs-on: 'ubuntu-latest'
68
+ strategy:
69
+ fail-fast: false
70
+ matrix:
71
+ ruby_version:
72
+ - 2.5
73
+ steps:
74
+ - uses: actions/checkout@v2
75
+ with:
76
+ fetch-depth: 5
77
+ - name: "Set up Ruby ${{ matrix.ruby_version }}"
78
+ uses: ruby/setup-ruby@v1
79
+ with:
80
+ ruby-version: ${{ matrix.ruby_version }}
81
+ bundler-cache: true
82
+ - name: Check Style Offenses
83
+ run: bundle exec rubocop -S -D
84
+
85
+ gem_build:
86
+ if: "!contains(github.event.commits[0].message, '[ci skip]')"
87
+ name: "Test Gem build (Ruby ${{ matrix.ruby_version }})"
88
+ runs-on: 'ubuntu-latest'
89
+ strategy:
90
+ fail-fast: false
91
+ matrix:
92
+ ruby_version:
93
+ - 2.5
94
+ steps:
95
+ - uses: actions/checkout@v2
96
+ with:
97
+ fetch-depth: 5
98
+ - name: "Set up Ruby ${{ matrix.ruby_version }}"
99
+ uses: ruby/setup-ruby@v1
100
+ with:
101
+ ruby-version: ${{ matrix.ruby_version }}
102
+ bundler-cache: true
103
+ - name: Test Gem build
104
+ run: bundle exec gem build jekyll-paginate.gemspec
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ spec/dest
16
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,36 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+ rvm:
5
+ - 2.2
6
+ - 2.1
7
+ - 2.0
8
+ - 1.9.3
9
+ before_script: bundle update
10
+ script: script/cibuild
11
+ notifications:
12
+ irc:
13
+ on_success: change
14
+ on_failure: change
15
+ channels:
16
+ - irc.freenode.org#jekyll
17
+ template:
18
+ - '%{repository}#%{build_number} (%{branch}) %{message} %{build_url}'
19
+ email:
20
+ on_success: never
21
+ on_failure: never
22
+
23
+ matrix:
24
+ exclude:
25
+ - rvm: 1.9.3
26
+ env: JEKYLL_VERSION=3.0.0
27
+ - env: JEKYLL_VERSION=2.4
28
+ rvm: 2.1
29
+ - rvm: 2.2
30
+ env: JEKYLL_VERSION=2.4
31
+
32
+ env:
33
+ matrix:
34
+ - ""
35
+ - JEKYLL_VERSION=2.4
36
+ - JEKYLL_VERSION=3.0.0
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-paginate-data.gemspec
4
+ gemspec
5
+
6
+ if ENV["JEKYLL_VERSION"]
7
+ gem "jekyll", ENV["JEKYLL_VERSION"]
8
+ end
data/History.markdown ADDED
@@ -0,0 +1,20 @@
1
+ ## HEAD
2
+
3
+ ### Minor Enhancements
4
+
5
+ * Throw an error if the pagination path doesn't contain `:num`. (#19)
6
+
7
+ ### Development Fixes
8
+
9
+ * Upgrade to the new Travis build environment and use their built-in caching (#20)
10
+ * Add GitHub Actions CI (#46)
11
+
12
+ ## 1.1.0 / 2014-10-14
13
+
14
+ ### Minor Enhancements
15
+
16
+ * Filter out posts that have `hidden: true` in front matter (#13)
17
+
18
+ ### Development Fixes
19
+
20
+ * Fix tests for rspec 3. (#9)
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2025 Bastian Greshake Tzovaras
2
+ Copyright (c) 2014 Parker Moore
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Jekyll::DataPaginate
2
+
3
+ This is a modified version of `jekyll-paginate`, the default pagination generator gem for Jekyll.
4
+
5
+ `Jekyll::DataPaginate` allows you to paginate over a collection of data files, by setting a few parameters in your `_config.yml` for Jekyll.
6
+
7
+ **Currently, this gem only works for paginating a data collection that is based on a collection of files that are within a subfolder of `_data`**
8
+
9
+ For example, if your `example` data file folder looks like this:
10
+
11
+ ```
12
+ ❯ ls _data/example/*
13
+ _data/example/1.yaml _data/example/2.yaml _data/example/3.yaml
14
+ ```
15
+
16
+ this gem will give you three "posts" to paginate.
17
+
18
+ The gem is setup to work side-by-side with the regular pagination feature for posts/pages.
19
+
20
+ You can see a [small example of this gem in action at my website](https://tzovar.as/links), with the corresponding code residing at [Codeberg too](https://codeberg.org/gedankenstuecke/pages-source).
21
+
22
+
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ gem 'jekyll-paginate-data'
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ Or install it yourself as:
35
+
36
+ $ gem install jekyll-paginate-data
37
+
38
+ ## Usage
39
+
40
+ You will have to activate this gem in your Jekyll `_config.yml`:
41
+
42
+ ```
43
+ plugins:
44
+ - jekyll-paginate-data
45
+ ```
46
+
47
+ You will have to configure the following three parameters in your `_config.yml` too:
48
+
49
+ - `data_paginate`, the number of items per page
50
+ - `data_paginate_key`, which is the sub-folder of `_data` over which you want to paginate
51
+ - `data_paginate_path`, the format & path the pagination should take
52
+
53
+ An example configuration could be:
54
+
55
+ ```
56
+ data_paginate: 25
57
+ data_paginate_key: "links"
58
+ data_paginate_path: "links/:num"
59
+ ```
60
+
61
+ ### Template requirement
62
+ You will need to have an `index.html` file that corresponds to your `data_paginate_path`, e.g. if you use `links/:num` as your path, then you will need to have a `links/index.html` template file in your Jekyll.
63
+
64
+ **Note: Your `index.html` can not define a `permalink`!**
65
+
66
+ In the template you can access the paginator via `{{ paginator }}`, just as the regular paginator, with the following options:
67
+
68
+ ```
69
+ # {"paginator" => { "page" => <Number>,
70
+ # "per_page" => <Number>,
71
+ # "posts" => [<Post>],
72
+ # "total_posts" => <Number>,
73
+ # "total_pages" => <Number>,
74
+ # "previous_page" => <Number>,
75
+ # "next_page_path => <Path>,
76
+ # "previous_page_path => <Path>,
77
+ # "next_page" => <Number> }}
78
+ ```
79
+
80
+ ## Contributing
81
+
82
+ If you have any improvement suggestions or would like to contribute code, please do!
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
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-data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-paginate-data"
8
+ spec.version = Jekyll::DataPaginate::VERSION
9
+ spec.authors = ["Bastian Greshake Tzovaras"]
10
+ spec.email = ["bgreshake@proton.me"]
11
+ spec.summary = %q{Pagination for data files of Jekyll}
12
+ spec.homepage = "https://codeberg.org/gedankenstuecke/jekyll-paginate-data"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "jekyll", ">= 2.0", "< 5.0"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "rubocop-jekyll"
25
+ end
@@ -0,0 +1,140 @@
1
+ module Jekyll
2
+ module DataPaginate
3
+ class DataPager
4
+ attr_reader :page, :per_page, :posts, :total_posts, :total_pages,
5
+ :previous_page, :previous_page_path, :next_page, :next_page_path
6
+
7
+ # Calculate the number of pages.
8
+ #
9
+ # all_posts - The Array of all Posts.
10
+ # per_page - The Integer of entries per page.
11
+ #
12
+ # Returns the Integer number of pages.
13
+ def self.calculate_pages(all_posts, per_page)
14
+ (all_posts.size.to_f / per_page.to_i).ceil
15
+ end
16
+
17
+ # Determine if pagination is enabled the site.
18
+ #
19
+ # site - the Jekyll::Site object
20
+ #
21
+ # Returns true if pagination is enabled, false otherwise.
22
+ def self.pagination_enabled?(site)
23
+ !site.config['data_paginate'].nil? &&
24
+ site.data[site.config['data_paginate_key']].size > 0
25
+ end
26
+
27
+ # Static: Determine if a page is a possible candidate to be a template page.
28
+ # Page's name must be `index.html` and exist in any of the directories
29
+ # between the site source and `paginate_path`.
30
+ #
31
+ # config - the site configuration hash
32
+ # page - the Jekyll::Page about which we're inquiring
33
+ #
34
+ # Returns true if the
35
+ def self.pagination_candidate?(config, page)
36
+ page_dir = File.dirname(File.expand_path(remove_leading_slash(page.path), config['source']))
37
+ paginate_path = remove_leading_slash(config['data_paginate_path'])
38
+ paginate_path = File.expand_path(paginate_path, config['source'])
39
+ page.name == 'index.html' &&
40
+ in_hierarchy(config['source'], page_dir, File.dirname(paginate_path))
41
+ end
42
+
43
+ # Determine if the subdirectories of the two paths are the same relative to source
44
+ #
45
+ # source - the site source
46
+ # page_dir - the directory of the Jekyll::Page
47
+ # paginate_path - the absolute paginate path (from root of FS)
48
+ #
49
+ # Returns whether the subdirectories are the same relative to source
50
+ def self.in_hierarchy(source, page_dir, paginate_path)
51
+ return false if paginate_path == File.dirname(paginate_path)
52
+ return false if paginate_path == Pathname.new(source).parent
53
+ page_dir == paginate_path ||
54
+ in_hierarchy(source, page_dir, File.dirname(paginate_path))
55
+ end
56
+
57
+ # Static: Return the pagination path of the page
58
+ #
59
+ # site - the Jekyll::Site object
60
+ # num_page - the pagination page number
61
+ #
62
+ # Returns the pagination path as a string
63
+ def self.paginate_path(site, num_page)
64
+ return nil if num_page.nil?
65
+ return DataPagination.first_page_url(site) if num_page <= 1
66
+ format = site.config['data_paginate_path']
67
+ if format.include?(":num")
68
+ format = format.sub(':num', num_page.to_s)
69
+ else
70
+ raise ArgumentError.new("Invalid pagination path: '#{format}'. It must include ':num'.")
71
+ end
72
+ ensure_leading_slash(format)
73
+ end
74
+
75
+ # Static: Return a String version of the input which has a leading slash.
76
+ # If the input already has a forward slash in position zero, it will be
77
+ # returned unchanged.
78
+ #
79
+ # path - a String path
80
+ #
81
+ # Returns the path with a leading slash
82
+ def self.ensure_leading_slash(path)
83
+ path[0..0] == "/" ? path : "/#{path}"
84
+ end
85
+
86
+ # Static: Return a String version of the input without a leading slash.
87
+ #
88
+ # path - a String path
89
+ #
90
+ # Returns the input without the leading slash
91
+ def self.remove_leading_slash(path)
92
+ ensure_leading_slash(path)[1..-1]
93
+ end
94
+
95
+ # Initialize a new DataPager.
96
+ #
97
+ # site - the Jekyll::Site object
98
+ # page - The Integer page number.
99
+ # all_posts - The Array of all the site's Posts.
100
+ # num_pages - The Integer number of pages or nil if you'd like the number
101
+ # of pages calculated.
102
+ def initialize(site, page, all_posts, num_pages = nil)
103
+ @page = page
104
+ @per_page = site.config['data_paginate'].to_i
105
+ @total_pages = num_pages || DataPager.calculate_pages(all_posts, @per_page)
106
+
107
+ if @page > @total_pages
108
+ raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}"
109
+ end
110
+
111
+ init = (@page - 1) * @per_page
112
+ offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1)
113
+
114
+ @total_posts = all_posts.size
115
+ @posts = all_posts[init..offset]
116
+ @previous_page = @page != 1 ? @page - 1 : nil
117
+ @previous_page_path = DataPager.paginate_path(site, @previous_page)
118
+ @next_page = @page != @total_pages ? @page + 1 : nil
119
+ @next_page_path = DataPager.paginate_path(site, @next_page)
120
+ end
121
+
122
+ # Convert this DataPager's data to a Hash suitable for use by Liquid.
123
+ #
124
+ # Returns the Hash representation of this DataPager.
125
+ def to_liquid
126
+ {
127
+ 'page' => page,
128
+ 'per_page' => per_page,
129
+ 'posts' => posts,
130
+ 'total_posts' => total_posts,
131
+ 'total_pages' => total_pages,
132
+ 'previous_page' => previous_page,
133
+ 'previous_page_path' => previous_page_path,
134
+ 'next_page' => next_page,
135
+ 'next_page_path' => next_page_path
136
+ }
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,90 @@
1
+ module Jekyll
2
+ module DataPaginate
3
+ class DataPagination < Generator
4
+ # This generator is safe from arbitrary code execution.
5
+ safe true
6
+
7
+ # This generator should be passive with regard to its execution
8
+ priority :lowest
9
+
10
+ # Generate paginated pages if necessary.
11
+ #
12
+ # site - The Site.
13
+ #
14
+ # Returns nothing.
15
+ def generate(site)
16
+ if DataPager.pagination_enabled?(site)
17
+ Jekyll.logger.warn "DataPagination:", "activated data pagination"
18
+ if template = self.class.template_page(site)
19
+ paginate(site, template)
20
+ else
21
+ Jekyll.logger.warn "DataPagination:", "DataPagination is enabled, but I couldn't find " +
22
+ "an index.html page to use as the pagination template. Skipping pagination."
23
+ end
24
+ end
25
+ end
26
+
27
+ # Paginates the blog's posts. Renders the index.html file into paginated
28
+ # directories, e.g.: page2/index.html, page3/index.html, etc and adds more
29
+ # site-wide data.
30
+ #
31
+ # site - The Site.
32
+ # page - The index.html Page that requires pagination.
33
+ #
34
+ # {"paginator" => { "page" => <Number>,
35
+ # "per_page" => <Number>,
36
+ # "posts" => [<Post>],
37
+ # "total_posts" => <Number>,
38
+ # "total_pages" => <Number>,
39
+ # "previous_page" => <Number>,
40
+ # "next_page" => <Number> }}
41
+ def paginate(site, page)
42
+ all_posts_t = site.site_payload['site']['data'][site.config['data_paginate_key']]
43
+ all_posts = all_posts_t.map { |p| p[1] }.reverse
44
+ pages = DataPager.calculate_pages(all_posts, site.config['data_paginate'].to_i)
45
+ (1..pages).each do |num_page|
46
+ pager = DataPager.new(site, num_page, all_posts, pages)
47
+ # the original jekyll-paginate rocks num_page > 1 but that leads to
48
+ # the first page having no data at all. I don't understand the jekyll
49
+ # internals enough to know why, but just going with "do this for all pages"
50
+ # seems to fix it :shrug:
51
+ if num_page > 0
52
+ newpage = Page.new(site, site.source, page.dir, page.name)
53
+ newpage.pager = pager
54
+ newpage.dir = DataPager.paginate_path(site, num_page)
55
+ site.pages << newpage
56
+ else
57
+ page.pager = pager
58
+ end
59
+ end
60
+ end
61
+
62
+ # Static: Fetch the URL of the template page. Used to determine the
63
+ # path to the first pager in the series.
64
+ #
65
+ # site - the Jekyll::Site object
66
+ #
67
+ # Returns the url of the template page
68
+ def self.first_page_url(site)
69
+ if page = DataPagination.template_page(site)
70
+ page.url
71
+ else
72
+ nil
73
+ end
74
+ end
75
+
76
+ # Public: Find the Jekyll::Page which will act as the pager template
77
+ #
78
+ # site - the Jekyll::Site object
79
+ #
80
+ # Returns the Jekyll::Page which will act as the pager template
81
+ def self.template_page(site)
82
+ site.pages.select do |page|
83
+ DataPager.pagination_candidate?(site.config, page)
84
+ end.sort do |one, two|
85
+ two.path.size <=> one.path.size
86
+ end.first
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module DataPaginate
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "jekyll-paginate-data/version"
2
+ require "jekyll-paginate-data/pager"
3
+ require "jekyll-paginate-data/pagination"
4
+
5
+ module Jekyll
6
+ module DataPaginate
7
+ end
8
+ end
data/script/bootstrap ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ bundle install
data/script/cibuild ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ bundle exec rspec
@@ -0,0 +1,164 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe(Jekyll::DataPaginate::DataPager) do
4
+
5
+ it "calculate number of pages" do
6
+ expect(described_class.calculate_pages([], '2')).to eql(0)
7
+ expect(described_class.calculate_pages([1], '2')).to eql(1)
8
+ expect(described_class.calculate_pages([1,2], '2')).to eql(1)
9
+ expect(described_class.calculate_pages([1,2,3], '2')).to eql(2)
10
+ expect(described_class.calculate_pages([1,2,3,4], '2')).to eql(2)
11
+ expect(described_class.calculate_pages([1,2,3,4,5], '2')).to eql(3)
12
+ end
13
+
14
+ context "with paginate_path set to a subdirectory with no index.html" do
15
+ let(:site) { build_site({'data_paginate_path' => '/blog/page-:num'}) }
16
+
17
+ it "determines the correct pagination path for each page" do
18
+ if Jekyll::VERSION < '3.0.0'
19
+ expect(described_class.paginate_path(site, 1)).to eql("/index.html")
20
+ else
21
+ expect(described_class.paginate_path(site, 1)).to eql("/")
22
+ end
23
+
24
+ expect(described_class.paginate_path(site, 2)).to eql("/blog/page-2")
25
+ end
26
+ end
27
+
28
+ context "with paginate_path set to a subdirectory with no index.html with num pages being in subdirectories" do
29
+ let(:site) { build_site({'data_paginate_path' => '/blog/page/:num'}) }
30
+
31
+ it "determines the correct pagination path for each page" do
32
+ if Jekyll::VERSION < '3.0.0'
33
+ expect(described_class.paginate_path(site, 1)).to eql("/index.html")
34
+ else
35
+ expect(described_class.paginate_path(site, 1)).to eql("/")
36
+ end
37
+
38
+ expect(described_class.paginate_path(site, 2)).to eql("/blog/page/2")
39
+ end
40
+ end
41
+
42
+ context "with paginate_path set to a subdirectory wherein an index.html exists" do
43
+ let(:site) { build_site({'data_paginate_path' => '/contacts/page:num'}) }
44
+
45
+ it "determines the correct pagination path for each page" do
46
+ if Jekyll::VERSION < '3.0.0'
47
+ expect(described_class.paginate_path(site, 1)).to eql("/contacts/index.html")
48
+ else
49
+ expect(described_class.paginate_path(site, 1)).to eql("/contacts/")
50
+ end
51
+
52
+ expect(described_class.paginate_path(site, 2)).to eql("/contacts/page2")
53
+ end
54
+ end
55
+
56
+ context "with paginate_path set to a subdir wherein an index.html exists with pages in subdirs" do
57
+ let(:site) { build_site({'data_paginate_path' => '/contacts/page/:num'}) }
58
+
59
+ it "determines the correct pagination path for each page" do
60
+ if Jekyll::VERSION < '3.0.0'
61
+ expect(described_class.paginate_path(site, 1)).to eql("/contacts/index.html")
62
+ else
63
+ expect(described_class.paginate_path(site, 1)).to eql("/contacts/")
64
+ end
65
+
66
+ expect(described_class.paginate_path(site, 2)).to eql("/contacts/page/2")
67
+ end
68
+ end
69
+
70
+ context "with an paginate_path devoid of :num" do
71
+ let(:site) { build_site({'data_paginate_path' => '/blog/page'}) }
72
+
73
+ it "determines the correct pagination path for each page" do
74
+ expect(-> { described_class.paginate_path(site, 1) }).to raise_error
75
+ end
76
+ end
77
+
78
+ context "pagination disabled" do
79
+ let(:site) { build_site('data_paginate' => nil) }
80
+
81
+ it "report that pagination is disabled" do
82
+ expect(described_class.pagination_enabled?(site)).to be_falsey
83
+ end
84
+ end
85
+
86
+ context "pagination enabled for 2" do
87
+ let(:site) { build_site('data_paginate' => 2, 'data_paginate_path' => '/blog/page-:num') }
88
+ if Jekyll::VERSION < '3.0.0'
89
+ let(:posts) { site.posts }
90
+ else
91
+ let(:posts) { site.posts.docs }
92
+ end
93
+
94
+ it "report that pagination is enabled" do
95
+ expect(described_class.pagination_enabled?(site)).to be_truthy
96
+ end
97
+
98
+ context "with 4 posts" do
99
+ if Jekyll::VERSION < '3.0.0'
100
+ let(:posts) { site.posts[1..4] }
101
+ else
102
+ let(:posts) { site.posts.docs[1..4] }
103
+ end
104
+
105
+ it "create first pager" do
106
+ pager = described_class.new(site, 1, posts)
107
+ expect(pager.posts.size).to eql(2)
108
+ expect(pager.total_pages).to eql(2)
109
+ expect(pager.previous_page).to be_nil
110
+ expect(pager.next_page).to eql(2)
111
+ end
112
+
113
+ it "create second pager" do
114
+ pager = described_class.new(site, 2, posts)
115
+ expect(pager.posts.size).to eql(2)
116
+ expect(pager.total_pages).to eql(2)
117
+ expect(pager.previous_page).to eql(1)
118
+ expect(pager.next_page).to be_nil
119
+ end
120
+
121
+ it "not create third pager" do
122
+ expect { described_class.new(site, 3, posts) }.to raise_error
123
+ end
124
+ end
125
+
126
+ context "with 5 posts" do
127
+ if Jekyll::VERSION < '3.0.0'
128
+ let(:posts) { site.posts[1..5] }
129
+ else
130
+ let(:posts) { site.posts.docs[1..5] }
131
+ end
132
+
133
+ it "create first pager" do
134
+ pager = described_class.new(site, 1, posts)
135
+ expect(pager.posts.size).to eql(2)
136
+ expect(pager.total_pages).to eql(3)
137
+ expect(pager.previous_page).to be_nil
138
+ expect(pager.next_page).to eql(2)
139
+ end
140
+
141
+ it "create second pager" do
142
+ pager = described_class.new(site, 2, posts)
143
+ expect(pager.posts.size).to eql(2)
144
+ expect(pager.total_pages).to eql(3)
145
+ expect(pager.previous_page).to eql(1)
146
+ expect(pager.next_page).to eql(3)
147
+ end
148
+
149
+ it "create third pager" do
150
+ pager = described_class.new(site, 3, posts)
151
+ expect(pager.posts.size).to eql(1)
152
+ expect(pager.total_pages).to eql(3)
153
+ expect(pager.previous_page).to eql(2)
154
+ expect(pager.next_page).to be_nil
155
+ end
156
+
157
+ it "not create fourth pager" do
158
+ expect { described_class.new(site, 4, posts) }.to raise_error(RuntimeError)
159
+ end
160
+
161
+ end
162
+ end
163
+
164
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ username: jekyll
2
+ name: Jekyll
@@ -0,0 +1,2 @@
1
+ username: hyde
2
+ name: Hyde
@@ -0,0 +1,2 @@
1
+ username: stevenson
2
+ name: Robert Louis Stevenson
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ ---
2
+ ---
@@ -0,0 +1,2 @@
1
+ ---
2
+ ---
@@ -0,0 +1,101 @@
1
+ require 'jekyll'
2
+ require File.expand_path("../lib/jekyll-paginate-data", File.dirname(__FILE__))
3
+
4
+ module TestMethods
5
+ def test_dir(*subdirs)
6
+ File.join(File.dirname(__FILE__), *subdirs)
7
+ end
8
+
9
+ def dest_dir(*subdirs)
10
+ test_dir('dest', *subdirs)
11
+ end
12
+
13
+ def source_dir(*subdirs)
14
+ test_dir('source', *subdirs)
15
+ end
16
+
17
+ def build_configs(overrides, base_hash = Jekyll::Configuration::DEFAULTS)
18
+ Jekyll::Utils.deep_merge_hashes(base_hash, overrides)
19
+ end
20
+
21
+ def site_configuration(overrides = {})
22
+ build_configs({
23
+ "source" => source_dir,
24
+ "destination" => dest_dir
25
+ }, build_configs(overrides))
26
+ end
27
+
28
+ def build_site(config = {})
29
+ site = Jekyll::Site.new(site_configuration(
30
+ {
31
+ "data_paginate" => 1,
32
+ "data_paginate_key" => "example",
33
+ # "data_paginate_path" => "contacts/:num"
34
+ }.merge(config)
35
+ ))
36
+ site.process
37
+ site
38
+ end
39
+ end
40
+
41
+ RSpec.configure do |config|
42
+ config.expect_with :rspec do |expectations|
43
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
44
+ end
45
+
46
+ # rspec-mocks config goes here. You can use an alternate test double
47
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
48
+ config.mock_with :rspec do |mocks|
49
+ # Prevents you from mocking or stubbing a method that does not exist on
50
+ # a real object. This is generally recommended, and will default to
51
+ # `true` in RSpec 4.
52
+ mocks.verify_partial_doubles = true
53
+ end
54
+
55
+ # These two settings work together to allow you to limit a spec run
56
+ # to individual examples or groups you care about by tagging them with
57
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
58
+ # get run.
59
+ config.filter_run :focus
60
+ config.run_all_when_everything_filtered = true
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
63
+ # For more details, see:
64
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
65
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ # config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = 'doc'
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+
100
+ include TestMethods
101
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-paginate-data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bastian Greshake Tzovaras
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-08-28 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: '5.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: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
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
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop-jekyll
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description:
90
+ email:
91
+ - bgreshake@proton.me
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".github/workflows/ci.yml"
97
+ - ".gitignore"
98
+ - ".rspec"
99
+ - ".travis.yml"
100
+ - Gemfile
101
+ - History.markdown
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - jekyll-paginate.gemspec
106
+ - lib/jekyll-paginate-data.rb
107
+ - lib/jekyll-paginate-data/pager.rb
108
+ - lib/jekyll-paginate-data/pagination.rb
109
+ - lib/jekyll-paginate-data/version.rb
110
+ - script/bootstrap
111
+ - script/cibuild
112
+ - spec/pager_spec.rb
113
+ - spec/pagination_spec.rb
114
+ - spec/source/_data/example/1.yaml
115
+ - spec/source/_data/example/2.yaml
116
+ - spec/source/_data/example/3.yaml
117
+ - spec/source/_posts/2014-05-20-blah.html
118
+ - spec/source/_posts/2014-05-21-bleh.html
119
+ - spec/source/_posts/2014-05-22-humor.html
120
+ - spec/source/_posts/2014-05-23-hey-there.html
121
+ - spec/source/_posts/2014-05-24-whateva.html
122
+ - spec/source/_posts/2014-05-25-oh-yes.html
123
+ - spec/source/contacts/index.html
124
+ - spec/source/index.html
125
+ - spec/spec_helper.rb
126
+ homepage: https://codeberg.org/gedankenstuecke/jekyll-paginate-data
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubygems_version: 3.5.11
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Pagination for data files of Jekyll
149
+ test_files:
150
+ - spec/pager_spec.rb
151
+ - spec/pagination_spec.rb
152
+ - spec/source/_data/example/1.yaml
153
+ - spec/source/_data/example/2.yaml
154
+ - spec/source/_data/example/3.yaml
155
+ - spec/source/_posts/2014-05-20-blah.html
156
+ - spec/source/_posts/2014-05-21-bleh.html
157
+ - spec/source/_posts/2014-05-22-humor.html
158
+ - spec/source/_posts/2014-05-23-hey-there.html
159
+ - spec/source/_posts/2014-05-24-whateva.html
160
+ - spec/source/_posts/2014-05-25-oh-yes.html
161
+ - spec/source/contacts/index.html
162
+ - spec/source/index.html
163
+ - spec/spec_helper.rb