jekyll-paginate-v2-redux 1.7.6
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 +7 -0
- data/CODE_OF_CONDUCT.md +86 -0
- data/Gemfile +8 -0
- data/LICENSE +22 -0
- data/README-AUTOPAGES.md +104 -0
- data/README-GENERATOR.md +520 -0
- data/README.md +77 -0
- data/Rakefile +16 -0
- data/jekyll-paginate-v2-redux.gemspec +32 -0
- data/lib/jekyll-paginate-v2-redux.rb +34 -0
- data/lib/jekyll-paginate-v2-redux/autopages/autoPages.rb +77 -0
- data/lib/jekyll-paginate-v2-redux/autopages/defaults.rb +29 -0
- data/lib/jekyll-paginate-v2-redux/autopages/pages/baseAutoPage.rb +60 -0
- data/lib/jekyll-paginate-v2-redux/autopages/pages/categoryAutoPage.rb +28 -0
- data/lib/jekyll-paginate-v2-redux/autopages/pages/collectionAutoPage.rb +28 -0
- data/lib/jekyll-paginate-v2-redux/autopages/pages/tagAutoPage.rb +28 -0
- data/lib/jekyll-paginate-v2-redux/autopages/utils.rb +74 -0
- data/lib/jekyll-paginate-v2-redux/generator/compatibilityUtils.rb +121 -0
- data/lib/jekyll-paginate-v2-redux/generator/defaults.rb +24 -0
- data/lib/jekyll-paginate-v2-redux/generator/paginationGenerator.rb +141 -0
- data/lib/jekyll-paginate-v2-redux/generator/paginationIndexer.rb +93 -0
- data/lib/jekyll-paginate-v2-redux/generator/paginationModel.rb +358 -0
- data/lib/jekyll-paginate-v2-redux/generator/paginationPage.rb +50 -0
- data/lib/jekyll-paginate-v2-redux/generator/paginator.rb +84 -0
- data/lib/jekyll-paginate-v2-redux/generator/utils.rb +109 -0
- data/lib/jekyll-paginate-v2-redux/version.rb +10 -0
- data/spec/generator/defaults_spec.rb +34 -0
- data/spec/generator/paginationPage_spec.rb +12 -0
- data/spec/generator/paginator_spec.rb +107 -0
- data/spec/generator/utils_spec.rb +67 -0
- data/spec/spec_helper.rb +13 -0
- metadata +139 -0
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Jekyll::Paginate V2
|
2
|
+
|
3
|
+
Pagination gem built specially for Jekyll 3 and newer that is fully backwards compatable and serves as an enhanced replacement for the previously built-in [jekyll-paginate gem](https://github.com/jekyll/jekyll-paginate). View it on [rubygems.org](https://rubygems.org/gems/jekyll-paginate-v2).
|
4
|
+
|
5
|
+
[](https://rubygems.org/gems/jekyll-paginate-v2)
|
6
|
+
[](https://travis-ci.org/sverrirs/jekyll-paginate-v2)
|
7
|
+
[](https://gemnasium.com/github.com/sverrirs/jekyll-paginate-v2)
|
8
|
+
[](https://codeclimate.com/github/sverrirs/jekyll-paginate-v2)
|
9
|
+
[](https://hakiri.io/github/sverrirs/jekyll-paginate-v2/master)
|
10
|
+
[](https://rubygems.org/gems/jekyll-paginate-v2)
|
11
|
+
|
12
|
+
Reach me at the [project issues](https://github.com/sverrirs/jekyll-paginate-v2/issues) section or via email at [jekyll@sverrirs.com](mailto:jekyll@sverrirs.com).
|
13
|
+
|
14
|
+
> The code was based on the original design of [jekyll-paginate](https://github.com/jekyll/jekyll-paginate) and features were sourced from discussions such as [#27](https://github.com/jekyll/jekyll-paginate/issues/27) (thanks [Günter Kits](https://github.com/gynter)).
|
15
|
+
|
16
|
+
* [Installation](#installation)
|
17
|
+
* [Example Sites](https://github.com/sverrirs/jekyll-paginate-v2/tree/master/examples)
|
18
|
+
* [Pagination Generator](#pagination-generator)
|
19
|
+
* [Auto-Pages](#auto-pages)
|
20
|
+
* [Issues / to-be-completed](#issues--to-be-completed)
|
21
|
+
* [How to Contribute](#contributing)
|
22
|
+
|
23
|
+
> _"Be excellent to each other"_
|
24
|
+
|
25
|
+
:heart:
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
```
|
30
|
+
gem install jekyll-paginate-v2
|
31
|
+
```
|
32
|
+
|
33
|
+
Update your [_config.yml](README-GENERATOR.md#site-configuration) and [pages](README-GENERATOR.md#page-configuration).
|
34
|
+
|
35
|
+
> Although fully backwards compatible, to enable the new features this gem needs slightly extended [site yml](README-GENERATOR.md#site-configuration) configuration and miniscule additional new front-matter for the [pages to paginate on](README-GENERATOR.md#page-configuration).
|
36
|
+
|
37
|
+
Now you're ready to run `jekyll serve` and your paginated files should be generated.
|
38
|
+
|
39
|
+
Please see the [Examples](https://github.com/sverrirs/jekyll-paginate-v2/tree/master/examples) for tips and tricks on how to configure the pagination logic.
|
40
|
+
|
41
|
+
|
42
|
+
## Pagination Generator
|
43
|
+
|
44
|
+
The [Pagination Generator](README-GENERATOR.md) forms the core of the pagination logic. Calculates and generates the pagination pages.
|
45
|
+
|
46
|
+
|
47
|
+
## Auto Pages
|
48
|
+
|
49
|
+
The [Auto-Pages](README-AUTOPAGES.md) is an optional feature that auto-magically generates paginated pages for all your tags, categories and collections.
|
50
|
+
|
51
|
+
|
52
|
+
## Issues / to-be-completed
|
53
|
+
|
54
|
+
* Unit-tests do not cover all critical code paths
|
55
|
+
* No integration tests yet [#2](https://github.com/jekyll/jekyll-paginate/pull/2)
|
56
|
+
* _Exclude_ filter not implemented [#6](https://github.com/jekyll/jekyll-paginate/issues/6)
|
57
|
+
* Elegant way of collecting and printing debug information during pagination
|
58
|
+
|
59
|
+
|
60
|
+
I welcome all testers and people willing to give me feedback and code reviews.
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
> Although this project is small it has a [code of conduct](CODE_OF_CONDUCT.md) that I hope everyone will do their best to follow when contributing to any aspects of this project. Be it discussions, issue reporting, documentation or programming.
|
65
|
+
|
66
|
+
If you don't want to open issues here on Github, send me your feedback by email at [jekyll@sverrirs.com](mailto:jekyll@sverrirs.com).
|
67
|
+
|
68
|
+
1. Fork it ( https://github.com/sverrirs/jekyll-paginate-v2/fork )
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Run the unit tests (`rake`)
|
71
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
+
5. Build the gem locally (`gem build jekyll-paginate-v2.gemspec`)
|
73
|
+
6. Test and verify the gem locally (`gem install ./jekyll-paginate-v2-x.x.x.gem`)
|
74
|
+
7. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
8. Create new Pull Request
|
76
|
+
|
77
|
+
Note: This project uses [semantic versioning](http://semver.org/).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
#$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w[lib]))
|
5
|
+
#require 'lib/jekyll-paginate-v2/version'
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.libs.push 'lib'
|
9
|
+
t.libs.push 'specs'
|
10
|
+
t.verbose = true
|
11
|
+
t.pattern = "spec/**/*_spec.rb"
|
12
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Run tests"
|
16
|
+
task :default => [:test]
|
@@ -0,0 +1,32 @@
|
|
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-v2-redux/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jekyll-paginate-v2-redux"
|
8
|
+
spec.version = Jekyll::PaginateV2::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.required_ruby_version = '>= 2.0.0' # Same as Jekyll
|
11
|
+
spec.date = DateTime.now.strftime('%Y-%m-%d')
|
12
|
+
spec.authors = ["Sverrir Sigmundarson"]
|
13
|
+
spec.email = ["jekyll@sverrirs.com"]
|
14
|
+
spec.homepage = "https://github.com/sverrirs/jekyll-paginate-v2-redux"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.summary = %q{Pagination Generator for Jekyll 3}
|
18
|
+
spec.description = %q{An enhanced zero-configuration in-place replacement for the now decomissioned built-in jekyll-paginate gem. This pagination gem offers full backwards compatability as well as a slew of new frequently requested features with minimal additional site and page configuration. Optional features include auto-generation of paginated collection, tag and category pages.}
|
19
|
+
|
20
|
+
spec.files = Dir['CODE_OF_CONDUCT.md', 'README*.md', 'LICENSE', 'Rakefile', '*.gemspec', 'Gemfile', 'lib/**/*', 'spec/**/*']
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
# Gem requires Jekyll to work
|
25
|
+
# ~> is the pessimistic operator and is equivalent to '>= 3.0', '< 4.0'
|
26
|
+
spec.add_runtime_dependency "jekyll", "~> 3.0"
|
27
|
+
|
28
|
+
# Development requires more
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
31
|
+
spec.add_development_dependency "minitest", '~> 5.4'
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Jekyll::Paginate V2 is a gem built for Jekyll 3 that generates pagiatation for posts, collections, categories and tags.
|
2
|
+
#
|
3
|
+
# It is based on https://github.com/jekyll/jekyll-paginate, the original Jekyll paginator
|
4
|
+
# which was decommissioned in Jekyll 3 release onwards. This code is currently not officially
|
5
|
+
# supported on Jekyll versions < 3.0 (although it might work)
|
6
|
+
#
|
7
|
+
# Author: Sverrir Sigmundarson
|
8
|
+
# Site: https://github.com/andrewbents/jekyll-paginate-v2-redux
|
9
|
+
# Distributed Under The MIT License (MIT) as described in the LICENSE file
|
10
|
+
# - https://opensource.org/licenses/MIT
|
11
|
+
|
12
|
+
require "jekyll-paginate-v2-redux/version"
|
13
|
+
# Files needed for the pagination generator
|
14
|
+
require "jekyll-paginate-v2-redux/generator/defaults"
|
15
|
+
require "jekyll-paginate-v2-redux/generator/compatibilityUtils"
|
16
|
+
require "jekyll-paginate-v2-redux/generator/utils"
|
17
|
+
require "jekyll-paginate-v2-redux/generator/paginationIndexer"
|
18
|
+
require "jekyll-paginate-v2-redux/generator/paginator"
|
19
|
+
require "jekyll-paginate-v2-redux/generator/paginationPage"
|
20
|
+
require "jekyll-paginate-v2-redux/generator/paginationModel"
|
21
|
+
require "jekyll-paginate-v2-redux/generator/paginationGenerator"
|
22
|
+
# Files needed for the auto category and tag pages
|
23
|
+
require "jekyll-paginate-v2-redux/autopages/utils"
|
24
|
+
require "jekyll-paginate-v2-redux/autopages/defaults"
|
25
|
+
require "jekyll-paginate-v2-redux/autopages/autoPages"
|
26
|
+
require "jekyll-paginate-v2-redux/autopages/pages/baseAutoPage"
|
27
|
+
require "jekyll-paginate-v2-redux/autopages/pages/categoryAutoPage"
|
28
|
+
require "jekyll-paginate-v2-redux/autopages/pages/collectionAutoPage"
|
29
|
+
require "jekyll-paginate-v2-redux/autopages/pages/tagAutoPage"
|
30
|
+
|
31
|
+
module Jekyll
|
32
|
+
module PaginateV2
|
33
|
+
end # module PaginateV2
|
34
|
+
end # module Jekyll
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module PaginateV2::AutoPages
|
3
|
+
|
4
|
+
#
|
5
|
+
# When the site has been read then go a head an generate the necessary extra pages
|
6
|
+
# This code is adapted from Stephen Crosby's code https://github.com/stevecrozz
|
7
|
+
Jekyll::Hooks.register :site, :post_read do |site|
|
8
|
+
|
9
|
+
# Get the configuration for the auto pages
|
10
|
+
autopage_config = Jekyll::Utils.deep_merge_hashes(DEFAULT, site.config['autopages'] || {})
|
11
|
+
pagination_config = Jekyll::Utils.deep_merge_hashes(Jekyll::PaginateV2::Generator::DEFAULT, site.config['pagination'] || {})
|
12
|
+
|
13
|
+
# If disabled then don't do anything
|
14
|
+
if !autopage_config['enabled'] || autopage_config['enabled'].nil?
|
15
|
+
Jekyll.logger.info "AutoPages:","Disabled/Not configured in site.config."
|
16
|
+
next ## Break the loop, could be an issue if the hook is called again though??
|
17
|
+
end
|
18
|
+
|
19
|
+
# TODO: Should I detect here and disable if we're running the legacy paginate code???!
|
20
|
+
|
21
|
+
# Simply gather all documents across all pages/posts/collections that we have
|
22
|
+
# we could be generating quite a few empty pages but the logic is just vastly simpler than trying to
|
23
|
+
# figure out what tag/category belong to which collection.
|
24
|
+
posts_to_use = Utils.collect_all_docs(site.collections)
|
25
|
+
|
26
|
+
###############################################
|
27
|
+
# Generate the Tag pages if enabled
|
28
|
+
createtagpage_lambda = lambda do | autopage_tag_config, pagination_config, layout_name, tag, tag_original_name |
|
29
|
+
site.pages << TagAutoPage.new(site, site.dest, autopage_tag_config, pagination_config, layout_name, tag, tag_original_name)
|
30
|
+
end
|
31
|
+
autopage_create(autopage_config, pagination_config, posts_to_use, 'tags', 'tags', createtagpage_lambda) # Call the actual function
|
32
|
+
|
33
|
+
|
34
|
+
###############################################
|
35
|
+
# Generate the category pages if enabled
|
36
|
+
createcatpage_lambda = lambda do | autopage_cat_config, pagination_config, layout_name, category, category_original_name |
|
37
|
+
site.pages << CategoryAutoPage.new(site, site.dest, autopage_cat_config, pagination_config, layout_name, category, category_original_name)
|
38
|
+
end
|
39
|
+
autopage_create(autopage_config, pagination_config,posts_to_use, 'categories', 'categories', createcatpage_lambda) # Call the actual function
|
40
|
+
|
41
|
+
###############################################
|
42
|
+
# Generate the Collection pages if enabled
|
43
|
+
createcolpage_lambda = lambda do | autopage_col_config, pagination_config, layout_name, coll_name, coll_original_name |
|
44
|
+
site.pages << CollectionAutoPage.new(site, site.dest, autopage_col_config, pagination_config, layout_name, coll_name, coll_original_name)
|
45
|
+
end
|
46
|
+
autopage_create(autopage_config, pagination_config,posts_to_use, 'collections', '__coll', createcolpage_lambda) # Call the actual function
|
47
|
+
|
48
|
+
end # Jekyll::Hooks
|
49
|
+
|
50
|
+
|
51
|
+
# STATIC: this function actually performs the steps to generate the autopages. It uses a lambda function to delegate the creation of the individual
|
52
|
+
# page types to the calling code (this way all features can reuse the logic).
|
53
|
+
#
|
54
|
+
def self.autopage_create(autopage_config, pagination_config, posts_to_use, configkey_name, indexkey_name, createpage_lambda )
|
55
|
+
if !autopage_config[configkey_name].nil?
|
56
|
+
ap_sub_config = autopage_config[configkey_name]
|
57
|
+
if ap_sub_config ['enabled']
|
58
|
+
Jekyll.logger.info "AutoPages:","Generating #{configkey_name} pages"
|
59
|
+
|
60
|
+
# Roll through all documents in the posts collection and extract the tags
|
61
|
+
index_keys = Utils.ap_index_posts_by(posts_to_use, indexkey_name) # Cannot use just the posts here, must use all things.. posts, collections...
|
62
|
+
|
63
|
+
index_keys.each do |index_key, value|
|
64
|
+
# Iterate over each layout specified in the config
|
65
|
+
ap_sub_config ['layouts'].each do | layout_name |
|
66
|
+
# Use site.dest here as these pages are never created in the actual source but only inside the _site folder
|
67
|
+
createpage_lambda.call(ap_sub_config, pagination_config, layout_name, index_key, value[-1]) # the last item in the value array will be the display name
|
68
|
+
end
|
69
|
+
end
|
70
|
+
else
|
71
|
+
Jekyll.logger.info "AutoPages:","#{configkey_name} pages are disabled/not configured in site.config."
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end # module PaginateV2
|
77
|
+
end # module Jekyll
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module PaginateV2::AutoPages
|
3
|
+
|
4
|
+
# The default configuration for the AutoPages
|
5
|
+
DEFAULT = {
|
6
|
+
'enabled' => false,
|
7
|
+
'tags' => {
|
8
|
+
'layouts' => ['autopage_tags.html'],
|
9
|
+
'title' => 'Posts tagged with :tag',
|
10
|
+
'permalink' => '/tag/:tag',
|
11
|
+
'enabled' => true
|
12
|
+
|
13
|
+
},
|
14
|
+
'categories' => {
|
15
|
+
'layouts' => ['autopage_category.html'],
|
16
|
+
'title' => 'Posts in category :cat',
|
17
|
+
'permalink' => '/category/:cat',
|
18
|
+
'enabled' => true
|
19
|
+
},
|
20
|
+
'collections' => {
|
21
|
+
'layouts' => ['autopage_collection.html'],
|
22
|
+
'title' => 'Posts in collection :coll',
|
23
|
+
'permalink' => '/collection/:coll',
|
24
|
+
'enabled' => true
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
end # module PaginateV2::AutoPages
|
29
|
+
end # module Jekyll
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module PaginateV2::AutoPages
|
3
|
+
|
4
|
+
class BaseAutoPage < Jekyll::Page
|
5
|
+
def initialize(site, base, autopage_config, pagination_config, layout_name, set_autopage_data_lambda, get_autopage_permalink_lambda, get_autopage_title_lambda, display_name)
|
6
|
+
@site = site
|
7
|
+
@base = base
|
8
|
+
@name = 'index.html'
|
9
|
+
|
10
|
+
layout_dir = '_layouts'
|
11
|
+
|
12
|
+
# Path is only used by the convertible module and accessed below when calling read_yaml
|
13
|
+
# Handling themes stored in a gem
|
14
|
+
@path = if site.in_theme_dir(site.source) == site.source # we're in a theme
|
15
|
+
site.in_theme_dir(site.source, layout_dir, layout_name)
|
16
|
+
else
|
17
|
+
site.in_source_dir(site.source, layout_dir, layout_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
self.process(@name) # Creates the base name and extension
|
21
|
+
self.read_yaml(File.join(site.source, layout_dir), layout_name)
|
22
|
+
|
23
|
+
# Merge the config with any config that might already be defined in the layout
|
24
|
+
pagination_layout_config = Jekyll::Utils.deep_merge_hashes( pagination_config, self.data['pagination'] || {} )
|
25
|
+
|
26
|
+
# Read any possible autopage overrides in the layout page
|
27
|
+
autopage_layout_config = Jekyll::Utils.deep_merge_hashes( autopage_config, self.data['autopages'] || {} )
|
28
|
+
|
29
|
+
# Now set the page specific pagination data
|
30
|
+
set_autopage_data_lambda.call(pagination_layout_config)
|
31
|
+
|
32
|
+
# Get permalink structure
|
33
|
+
permalink_formatted = get_autopage_permalink_lambda.call(autopage_layout_config['permalink'])
|
34
|
+
|
35
|
+
# Construct the title
|
36
|
+
page_title = autopage_layout_config['title']
|
37
|
+
|
38
|
+
# NOTE: Should we set this before calling read_yaml as that function validates the permalink structure
|
39
|
+
self.data['permalink'] = permalink_formatted
|
40
|
+
@url = File.join(permalink_formatted, @name)
|
41
|
+
@dir = permalink_formatted
|
42
|
+
|
43
|
+
self.data['layout'] = File.basename(layout_name, File.extname(layout_name))
|
44
|
+
self.data['title'] = get_autopage_title_lambda.call( page_title )
|
45
|
+
self.data['pagination'] = pagination_layout_config # Store the pagination configuration
|
46
|
+
|
47
|
+
# Add the auto page flag in there to be able to detect the page (necessary when figuring out where to load it from)
|
48
|
+
# TODO: Need to re-think this variable!!!
|
49
|
+
self.data['autopage'] = {"layout_path" => File.join( layout_dir, layout_name ), 'display_name' => display_name.to_s }
|
50
|
+
|
51
|
+
data.default_proc = proc do |_, key|
|
52
|
+
site.frontmatter_defaults.find(File.join(layout_dir, layout_name), type, key)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Trigger a page event
|
56
|
+
#Jekyll::Hooks.trigger :pages, :post_init, self
|
57
|
+
end #function initialize
|
58
|
+
end #class BaseAutoPage
|
59
|
+
end # module PaginateV2
|
60
|
+
end # module Jekyll
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module PaginateV2::AutoPages
|
3
|
+
|
4
|
+
class CategoryAutoPage < BaseAutoPage
|
5
|
+
def initialize(site, base, autopage_config, pagination_config, layout_name, category, category_name)
|
6
|
+
|
7
|
+
# Construc the lambda function to set the config values
|
8
|
+
# this function received the pagination config hash and manipulates it
|
9
|
+
set_autopage_data_lambda = lambda do | in_config |
|
10
|
+
in_config['category'] = category
|
11
|
+
end
|
12
|
+
|
13
|
+
get_autopage_permalink_lambda = lambda do |permalink_pattern|
|
14
|
+
return Utils.format_cat_macro(permalink_pattern, category)
|
15
|
+
end
|
16
|
+
|
17
|
+
get_autopage_title_lambda = lambda do |title_pattern|
|
18
|
+
return Utils.format_cat_macro(title_pattern, category)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Call the super constuctor with our custom lambda
|
22
|
+
super(site, base, autopage_config, pagination_config, layout_name, set_autopage_data_lambda, get_autopage_permalink_lambda, get_autopage_title_lambda, category_name)
|
23
|
+
|
24
|
+
end #function initialize
|
25
|
+
|
26
|
+
end #class CategoryAutoPage
|
27
|
+
end # module PaginateV2
|
28
|
+
end # module Jekyll
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module PaginateV2::AutoPages
|
3
|
+
|
4
|
+
class CollectionAutoPage < BaseAutoPage
|
5
|
+
def initialize(site, base, autopage_config, pagination_config, layout_name, collection, collection_name)
|
6
|
+
|
7
|
+
# Construc the lambda function to set the config values
|
8
|
+
# this function received the pagination config hash and manipulates it
|
9
|
+
set_autopage_data_lambda = lambda do | in_config |
|
10
|
+
in_config['collection'] = collection
|
11
|
+
end
|
12
|
+
|
13
|
+
get_autopage_permalink_lambda = lambda do |permalink_pattern|
|
14
|
+
return Utils.format_coll_macro(permalink_pattern, collection)
|
15
|
+
end
|
16
|
+
|
17
|
+
get_autopage_title_lambda = lambda do |title_pattern|
|
18
|
+
return Utils.format_coll_macro(title_pattern, collection)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Call the super constuctor with our custom lambda
|
22
|
+
super(site, base, autopage_config, pagination_config, layout_name, set_autopage_data_lambda, get_autopage_permalink_lambda, get_autopage_title_lambda, collection_name)
|
23
|
+
|
24
|
+
end #function initialize
|
25
|
+
|
26
|
+
end #class CollectionAutoPage
|
27
|
+
end # module PaginateV2
|
28
|
+
end # module Jekyll
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module PaginateV2::AutoPages
|
3
|
+
|
4
|
+
class TagAutoPage < BaseAutoPage
|
5
|
+
def initialize(site, base, autopage_config, pagination_config, layout_name, tag, tag_name)
|
6
|
+
|
7
|
+
# Construc the lambda function to set the config values,
|
8
|
+
# this function received the pagination config hash and manipulates it
|
9
|
+
set_autopage_data_lambda = lambda do | config |
|
10
|
+
config['tag'] = tag
|
11
|
+
end
|
12
|
+
|
13
|
+
get_autopage_permalink_lambda = lambda do |permalink_pattern|
|
14
|
+
return Utils.format_tag_macro(permalink_pattern, tag)
|
15
|
+
end
|
16
|
+
|
17
|
+
get_autopage_title_lambda = lambda do |title_pattern|
|
18
|
+
return Utils.format_tag_macro(title_pattern, tag)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Call the super constuctor with our custom lambda
|
22
|
+
super(site, base, autopage_config, pagination_config, layout_name, set_autopage_data_lambda, get_autopage_permalink_lambda, get_autopage_title_lambda, tag_name)
|
23
|
+
|
24
|
+
end #function initialize
|
25
|
+
|
26
|
+
end #class TagAutoPage
|
27
|
+
end # module PaginateV2
|
28
|
+
end # module Jekyll
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module PaginateV2::AutoPages
|
3
|
+
|
4
|
+
class Utils
|
5
|
+
|
6
|
+
# Static: returns a fully formatted string with the tag macro (:tag) replaced
|
7
|
+
#
|
8
|
+
def self.format_tag_macro(toFormat, tag)
|
9
|
+
return toFormat.sub(':tag', Jekyll::Utils.slugify(tag.to_s))
|
10
|
+
end #function format_tag_macro
|
11
|
+
|
12
|
+
# Static: returns a fully formatted string with the category macro (:cat) replaced
|
13
|
+
#
|
14
|
+
def self.format_cat_macro(toFormat, category)
|
15
|
+
return toFormat.sub(':cat', Jekyll::Utils.slugify(category.to_s))
|
16
|
+
end #function format_cat_macro
|
17
|
+
|
18
|
+
# Static: returns a fully formatted string with the collection macro (:coll) replaced
|
19
|
+
#
|
20
|
+
def self.format_coll_macro(toFormat, collection)
|
21
|
+
return toFormat.sub(':coll', Jekyll::Utils.slugify(collection.to_s))
|
22
|
+
end #function format_coll_macro
|
23
|
+
|
24
|
+
# Static: returns all documents from all collections defined in the hash of collections passed in
|
25
|
+
# excludes all pagination pages though
|
26
|
+
def self.collect_all_docs(site_collections)
|
27
|
+
coll = []
|
28
|
+
for coll_name, coll_data in site_collections
|
29
|
+
if !coll_data.nil?
|
30
|
+
coll += coll_data.docs.select { |doc| !doc.data.has_key?('pagination') }.each{ |doc| doc.data['__coll'] = coll_name } # Exclude all pagination pages and then for every page store it's collection name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return coll
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.ap_index_posts_by(all_posts, index_key)
|
37
|
+
return nil if all_posts.nil?
|
38
|
+
return all_posts if index_key.nil?
|
39
|
+
index = {}
|
40
|
+
for post in all_posts
|
41
|
+
next if post.data.nil?
|
42
|
+
next if !post.data.has_key?(index_key)
|
43
|
+
next if post.data[index_key].nil?
|
44
|
+
next if post.data[index_key].size <= 0
|
45
|
+
next if post.data[index_key].to_s.strip.length == 0
|
46
|
+
|
47
|
+
# Only tags and categories come as premade arrays, locale does not, so convert any data
|
48
|
+
# elements that are strings into arrays
|
49
|
+
post_data = post.data[index_key]
|
50
|
+
if post_data.is_a?(String)
|
51
|
+
post_data = post_data.split(/;|,|\s/)
|
52
|
+
end
|
53
|
+
|
54
|
+
for key in post_data
|
55
|
+
key = key.strip
|
56
|
+
# If the key is a delimetered list of values
|
57
|
+
# (meaning the user didn't use an array but a string with commas)
|
58
|
+
for raw_k_split in key.split(/;|,/)
|
59
|
+
k_split = raw_k_split.to_s.downcase.strip #Clean whitespace and junk
|
60
|
+
if !index.has_key?(k_split)
|
61
|
+
# Need to store the original key value here so that I can present it to the users as a page variable they can use (unmodified, e.g. tags not being 'sci-fi' but "Sci-Fi")
|
62
|
+
# Also, only interested in storing all the keys not the pages in this case
|
63
|
+
index[k_split.to_s] = [k_split.to_s, raw_k_split.to_s]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
return index
|
69
|
+
end # function index_posts_by
|
70
|
+
|
71
|
+
end # class Utils
|
72
|
+
|
73
|
+
end # module PaginateV2
|
74
|
+
end # module Jekyll
|