jekyll-paginate-cats 1.0.4 → 1.0.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b832a106d1eb388dece2b22b02071932515877b4
|
4
|
+
data.tar.gz: 6aff1db70130e4255949c2747202fd7317bad327
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc5fc9eee4a18aea52f5d2b09ed716263d1b70729d202a34496ec20d613fe111c50be40fe4056cd4d84cc913c29f2818876b816a98a19df605f307d0217276b6
|
7
|
+
data.tar.gz: cd227e103db2ade640bb0d7c7d33cfdae1761bcb9c34c041b2deebfe33c85ec4e115ae9e8327e27300a5ac82be93ab45fdbb040feba4754fb82c1d4cbc35c146
|
@@ -0,0 +1,69 @@
|
|
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
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Jekyll
|
2
2
|
module Paginate
|
3
|
-
module
|
3
|
+
module Cats
|
4
4
|
|
5
|
-
class
|
5
|
+
class CatPage < Jekyll::Page
|
6
6
|
# Attributes for Liquid templates
|
7
7
|
ATTRIBUTES_FOR_LIQUID = %w(
|
8
|
-
|
8
|
+
cat
|
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
|
-
#
|
23
|
-
def initialize(site, base,
|
24
|
-
layout = site.config['
|
22
|
+
# cat - The String cat
|
23
|
+
def initialize(site, base, cat)
|
24
|
+
layout = site.config['paginate_cat_layout'] || 'cat.html'
|
25
25
|
super(site, base, '_layouts', layout)
|
26
26
|
process('index.html')
|
27
27
|
|
28
|
-
# Get the
|
29
|
-
@
|
28
|
+
# Get the cat into layout using page.cat
|
29
|
+
@cat = cat
|
30
30
|
end
|
31
31
|
|
32
|
-
# Produce a
|
32
|
+
# Produce a cat object suitable for Liquid.
|
33
33
|
#
|
34
34
|
# Returns a String
|
35
|
-
def
|
36
|
-
if @
|
37
|
-
@
|
35
|
+
def cat
|
36
|
+
if @cat.is_a? String
|
37
|
+
@cat
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -42,3 +42,5 @@ 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
|
3
|
+
module Cats
|
4
4
|
|
5
5
|
class Pager < Jekyll::Paginate::Pager
|
6
|
-
# Update paginator.previous_page_path and next_page_path to add
|
6
|
+
# Update paginator.previous_page_path and next_page_path to add cat path
|
7
7
|
#
|
8
|
-
# site
|
9
|
-
#
|
8
|
+
# site - the Jekyll::Site object
|
9
|
+
# cat_path - cat path, eg /cat/web/
|
10
10
|
#
|
11
11
|
# Returns nothing.
|
12
|
-
def update_paginate_paths(site,
|
12
|
+
def update_paginate_paths(site, cat_path)
|
13
13
|
if @page > 1
|
14
|
-
@previous_page_path =
|
14
|
+
@previous_page_path = cat_path.sub(/(\/)+$/,'') + @previous_page_path
|
15
15
|
end
|
16
16
|
if @page < @total_pages
|
17
|
-
@next_page_path =
|
17
|
+
@next_page_path = cat_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.
|
28
|
+
def self.paginate_path_cat(site, num_page, cat_path, paginate_path = site.config['paginate_cat_path'])
|
29
29
|
return nil if num_page.nil?
|
30
|
-
return
|
31
|
-
format =
|
30
|
+
return cat_path if num_page <= 1
|
31
|
+
format = cat_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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-paginate-cats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenta Ng
|
@@ -59,9 +59,9 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- lib/jekyll-paginate-
|
63
|
-
- lib/jekyll-paginate-
|
64
|
-
- lib/jekyll-paginate-
|
62
|
+
- lib/jekyll-paginate-cats.rb
|
63
|
+
- lib/jekyll-paginate-cats/cat-page.rb
|
64
|
+
- lib/jekyll-paginate-cats/pager.rb
|
65
65
|
homepage: https://github.com/kentaccn/jekyll-paginate-cats
|
66
66
|
licenses:
|
67
67
|
- MIT
|
@@ -1,69 +0,0 @@
|
|
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
|