jekyll-paginate-categories 1.0.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
+ SHA1:
3
+ metadata.gz: 23890de65d6e4a988c7dc70001ab5277dd7d40b9
4
+ data.tar.gz: 75bfb2d0f0108eb8686611bb1d926adf94907415
5
+ SHA512:
6
+ metadata.gz: bb2a7fe8e5fc8f61001a74d9efc5453fee7d5a2bebb73149343a89b985f92c33ee386d725561daf322b068dd7c4900838f18d01c9bf8f8e9b23647bb5facca4c
7
+ data.tar.gz: f5616d9ac28b96e997e8c9f979a89c68f82a4eda8534aefc9407a89a2088af78bef7d3f421c079f8ebe2f5a80285812cd5f957b603a983cd496414c50c44cb9a
@@ -0,0 +1,69 @@
1
+ require 'jekyll'
2
+
3
+ module Jekyll
4
+ module Paginate
5
+ module Categories
6
+
7
+ # Internal requires
8
+ autoload :CategoryPage, 'jekyll-paginate-categories/category-page'
9
+ autoload :Pager, 'jekyll-paginate-categories/pager'
10
+
11
+ # Per-category pagination.
12
+ # Based on jekyll-paginate.
13
+ #
14
+ # paginate_category_basepath: category base path - eg, /category/:name/
15
+ # paginate_path: will be concatenated with paginate_category - eg /page/:num/
16
+ # paginate_category_layout: The layout name of the category layout (default: categories.html)
17
+ class CategoryPagination < Generator
18
+ safe true
19
+
20
+ # Generate paginated pages if necessary.
21
+ #
22
+ # site - The Site.
23
+ #
24
+ # Returns nothing.
25
+ def generate(site)
26
+ if site.config['paginate_category_basepath']
27
+ for category in site.categories.keys
28
+ paginate_category(site, category)
29
+ end
30
+ end
31
+ end
32
+
33
+ # Do the blog's posts pagination per category. Renders the index.html file into paginated
34
+ # directories (see paginate_category_basepath and paginate_path config) for these categories,
35
+ # e.g.: /categories/my-category/page2/index.html, /categories/my-category/page3/index.html, etc.
36
+ #
37
+ # site - The Site.
38
+ # category - The category to paginate.
39
+ #
40
+ # Returns nothing.
41
+ def paginate_category(site, category)
42
+ # Retrieve posts from that specific category.
43
+ all_posts = site.site_payload['site']['categories'][category]
44
+
45
+ # Category base path
46
+ category_path = site.config['paginate_category_basepath']
47
+ category_path = category_path.sub(':name', category.downcase)
48
+
49
+ # Count pages
50
+ nb_pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i)
51
+
52
+ # Create pages
53
+ (1..nb_pages).each do |current_num_page|
54
+ # Split posts into pages
55
+ pager = Pager.new(site, current_num_page, all_posts, nb_pages)
56
+ pager.update_paginate_paths(site, category_path)
57
+
58
+ # Create new page, based on category layout
59
+ newpage = CategoryPage.new(site, site.source, category)
60
+ newpage.pager = pager
61
+ newpage.dir = Pager.paginate_path_category(site, current_num_page, category_path)
62
+ site.pages << newpage
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,44 @@
1
+ module Jekyll
2
+ module Paginate
3
+ module Categories
4
+
5
+ class CategoryPage < Jekyll::Page
6
+ # Attributes for Liquid templates
7
+ ATTRIBUTES_FOR_LIQUID = %w(
8
+ category
9
+ content
10
+ dir
11
+ name
12
+ path
13
+ url
14
+ )
15
+
16
+ # Initialize a new Page.
17
+ #
18
+ # site - The Site object.
19
+ # base - The String path to the source.
20
+ # dir - The String path between the source and the file.
21
+ # name - The String filename of the file.
22
+ # category - The String category
23
+ def initialize(site, base, category)
24
+ layout = site.config['paginate_category_layout'] || 'category.html'
25
+ super(site, base, '_layouts', layout)
26
+ process('index.html')
27
+
28
+ # Get the category into layout using page.category
29
+ @category = category
30
+ end
31
+
32
+ # Produce a category object suitable for Liquid.
33
+ #
34
+ # Returns a String
35
+ def category
36
+ if @category.is_a? String
37
+ @category
38
+ end
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,39 @@
1
+ module Jekyll
2
+ module Paginate
3
+ module Categories
4
+
5
+ class Pager < Jekyll::Paginate::Pager
6
+ # Update paginator.previous_page_path and next_page_path to add category path
7
+ #
8
+ # site - the Jekyll::Site object
9
+ # category_path - category path, eg /category/web/
10
+ #
11
+ # Returns nothing.
12
+ def update_paginate_paths(site, category_path)
13
+ if @page > 1
14
+ @previous_page_path = category_path.sub(/(\/)+$/,'') + @previous_page_path
15
+ end
16
+ if @page < @total_pages
17
+ @next_page_path = category_path.sub(/(\/)+$/,'') + @next_page_path
18
+ end
19
+ end
20
+
21
+ # Static: Return the pagination path of the page
22
+ #
23
+ # site - the Jekyll::Site object
24
+ # num_page - the pagination page number
25
+ # paginate_path - the explicit paginate path, if provided
26
+ #
27
+ # Returns the pagination path as a string
28
+ def self.paginate_path_category(site, num_page, category_path, paginate_path = site.config['paginate_path'])
29
+ return nil if num_page.nil?
30
+ return category_path if num_page <= 1
31
+ format = category_path.sub(/(\/)+$/,'') + paginate_path
32
+ format = format.sub(':num', num_page.to_s)
33
+ ensure_leading_slash(format)
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-paginate-categories
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Julien Guyomard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-24 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.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll-paginate
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Automatically generate pagination for each category
56
+ email:
57
+ - julien@mangue.eu
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/jekyll-paginate-categories.rb
63
+ - lib/jekyll-paginate-categories/category-page.rb
64
+ - lib/jekyll-paginate-categories/pager.rb
65
+ homepage: https://github.com/jguyomard/jekyll-paginate-categories
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.6.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Generate Pagination for Jekyll Categories.
89
+ test_files: []