jekyll-paginate-cats 1.0.5 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b832a106d1eb388dece2b22b02071932515877b4
4
- data.tar.gz: 6aff1db70130e4255949c2747202fd7317bad327
3
+ metadata.gz: b1d4877fa75c43beb9e690e8c3a2d530ca421053
4
+ data.tar.gz: 7374bd21f236c2618a45b96a78d537236ece6cc5
5
5
  SHA512:
6
- metadata.gz: bc5fc9eee4a18aea52f5d2b09ed716263d1b70729d202a34496ec20d613fe111c50be40fe4056cd4d84cc913c29f2818876b816a98a19df605f307d0217276b6
7
- data.tar.gz: cd227e103db2ade640bb0d7c7d33cfdae1761bcb9c34c041b2deebfe33c85ec4e115ae9e8327e27300a5ac82be93ab45fdbb040feba4754fb82c1d4cbc35c146
6
+ metadata.gz: ac9f7e70587eaa0442837a5ca7ee9fe4dd6a659beb9f6fb9032f9cb9cddc8542c3cc069a9a72bf71727bcf9e038fbec53a64c99b8f537725f4bf3bd050b4da2a
7
+ data.tar.gz: 8cb798afdb4ca9f0501ef7af62be617f8c4f0b3b2d2890ef62c6226732288941f5aa54cffc17a29285ef38b41dcd3305aa756eb470895d4f4738cc9c3c533bba
@@ -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.strip.gsub(' ', '-').gsub(/[^\w-]/, ''))
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
@@ -1,11 +1,11 @@
1
1
  module Jekyll
2
2
  module Paginate
3
- module Cats
3
+ module Categories
4
4
 
5
- class CatPage < Jekyll::Page
5
+ class CategoryPage < Jekyll::Page
6
6
  # Attributes for Liquid templates
7
7
  ATTRIBUTES_FOR_LIQUID = %w(
8
- cat
8
+ category
9
9
  content
10
10
  dir
11
11
  name
@@ -19,22 +19,22 @@ module Jekyll
19
19
  # base - The String path to the source.
20
20
  # dir - The String path between the source and the file.
21
21
  # name - The String filename of the file.
22
- # cat - The String cat
23
- def initialize(site, base, cat)
24
- layout = site.config['paginate_cat_layout'] || 'cat.html'
22
+ # category - The String category
23
+ def initialize(site, base, category)
24
+ layout = site.config['paginate_category_layout'] || 'category.html'
25
25
  super(site, base, '_layouts', layout)
26
26
  process('index.html')
27
27
 
28
- # Get the cat into layout using page.cat
29
- @cat = cat
28
+ # Get the category into layout using page.category
29
+ @category = category
30
30
  end
31
31
 
32
- # Produce a cat object suitable for Liquid.
32
+ # Produce a category object suitable for Liquid.
33
33
  #
34
34
  # Returns a String
35
- def cat
36
- if @cat.is_a? String
37
- @cat
35
+ def category
36
+ if @category.is_a? String
37
+ @category
38
38
  end
39
39
  end
40
40
  end
@@ -42,5 +42,3 @@ module Jekyll
42
42
  end
43
43
  end
44
44
  end
45
-
46
-
@@ -1,20 +1,20 @@
1
1
  module Jekyll
2
2
  module Paginate
3
- module Cats
3
+ module Categories
4
4
 
5
5
  class Pager < Jekyll::Paginate::Pager
6
- # Update paginator.previous_page_path and next_page_path to add cat path
6
+ # Update paginator.previous_page_path and next_page_path to add category path
7
7
  #
8
- # site - the Jekyll::Site object
9
- # cat_path - cat path, eg /cat/web/
8
+ # site - the Jekyll::Site object
9
+ # category_path - category path, eg /category/web/
10
10
  #
11
11
  # Returns nothing.
12
- def update_paginate_paths(site, cat_path)
12
+ def update_paginate_paths(site, category_path)
13
13
  if @page > 1
14
- @previous_page_path = cat_path.sub(/(\/)+$/,'') + @previous_page_path
14
+ @previous_page_path = category_path.sub(/(\/)+$/,'') + @previous_page_path
15
15
  end
16
16
  if @page < @total_pages
17
- @next_page_path = cat_path.sub(/(\/)+$/,'') + @next_page_path
17
+ @next_page_path = category_path.sub(/(\/)+$/,'') + @next_page_path
18
18
  end
19
19
  end
20
20
 
@@ -25,10 +25,10 @@ module Jekyll
25
25
  # paginate_path - the explicit paginate path, if provided
26
26
  #
27
27
  # Returns the pagination path as a string
28
- def self.paginate_path_cat(site, num_page, cat_path, paginate_path = site.config['paginate_cat_path'])
28
+ def self.paginate_path_category(site, num_page, category_path, paginate_path = site.config['paginate_category_path'])
29
29
  return nil if num_page.nil?
30
- return cat_path if num_page <= 1
31
- format = cat_path.sub(/(\/)+$/,'') + paginate_path
30
+ return category_path if num_page <= 1
31
+ format = category_path.sub(/(\/)+$/,'') + paginate_path
32
32
  format = format.sub(':num', num_page.to_s)
33
33
  ensure_leading_slash(format)
34
34
  end
@@ -36,4 +36,4 @@ module Jekyll
36
36
 
37
37
  end
38
38
  end
39
- end
39
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-paginate-cats
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
- - Kenta Ng
7
+ - Aweseome Kenta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -59,9 +59,9 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - lib/jekyll-paginate-cats.rb
63
- - lib/jekyll-paginate-cats/cat-page.rb
64
- - lib/jekyll-paginate-cats/pager.rb
62
+ - lib/jekyll-paginate-categories.rb
63
+ - lib/jekyll-paginate-categories/category-page.rb
64
+ - lib/jekyll-paginate-categories/pager.rb
65
65
  homepage: https://github.com/kentaccn/jekyll-paginate-cats
66
66
  licenses:
67
67
  - MIT
@@ -85,5 +85,5 @@ rubyforge_project:
85
85
  rubygems_version: 2.6.8
86
86
  signing_key:
87
87
  specification_version: 4
88
- summary: Generate Pagination for Jekyll Categories.
88
+ summary: Generate Pagination for Jekyll Categories with custom categories path.
89
89
  test_files: []
@@ -1,69 +0,0 @@
1
- require 'jekyll'
2
-
3
- module Jekyll
4
- module Paginate
5
- module Cats
6
-
7
- # Internal requires
8
- autoload :CatPage, 'jekyll-paginate-cats/cat-page'
9
- autoload :Pager, 'jekyll-paginate-cats/pager'
10
-
11
- # Per-cat pagination.
12
- # Based on jekyll-paginate.
13
- #
14
- # paginate_cat_basepath: cat base path - eg, /cat/:name/
15
- # paginate_path: will be concatenated with paginate_cat - eg /page/:num/
16
- # paginate_cat_layout: The layout name of the cat layout (default: cats.html)
17
- class CatPagination < 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_cat_basepath']
27
- for cat in site.cats.keys
28
- paginate_cat(site, cat)
29
- end
30
- end
31
- end
32
-
33
- # Do the blog's posts pagination per cat. Renders the index.html file into paginated
34
- # directories (see paginate_cat_basepath and paginate_path config) for these cats,
35
- # e.g.: /cats/my-cat/page2/index.html, /cats/my-cat/page3/index.html, etc.
36
- #
37
- # site - The Site.
38
- # cat - The cat to paginate.
39
- #
40
- # Returns nothing.
41
- def paginate_cat(site, cat)
42
- # Retrieve posts from that specific cat.
43
- all_posts = site.site_payload['site']['cats'][cat]
44
-
45
- # cat base path
46
- cat_path = site.config['paginate_cat_basepath']
47
- cat_path = cat_path.sub(':name', cat.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, ''))
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, cat_path)
57
-
58
- # Create new page, based on cat layout
59
- newpage = CatPage.new(site, site.source, cat)
60
- newpage.pager = pager
61
- newpage.dir = Pager.paginate_path_cat(site, current_num_page, cat_path)
62
- site.pages << newpage
63
- end
64
- end
65
- end
66
-
67
- end
68
- end
69
- end