jekyll-paginate-tags 1.0.2

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: c014e97418381fd6a0f03495fa7d19f5244532b9
4
+ data.tar.gz: 36222ec5d19e9a7cb2085815458bfeeb052c437e
5
+ SHA512:
6
+ metadata.gz: 4821db1faab36b6be50ef7a6a841e5da147de0c2d5ce134310058ade6338282e75e3bcec39fe59063b80cd2d25250efed10833e5f3f5507b19df5769b2c3fc1e
7
+ data.tar.gz: d1e4d69c719c3d93011abfe53f1d268ba978795f8e52cd883229ef20efc4f78f34ed3013e025a6ccd630276885c3864cda03177064df84211de1e4b1921efdf3
@@ -0,0 +1,39 @@
1
+ module Jekyll
2
+ module Paginate
3
+ module Tags
4
+
5
+ class Pager < Jekyll::Paginate::Pager
6
+ # Update paginator.previous_page_path and next_page_path to add tag path
7
+ #
8
+ # site - the Jekyll::Site object
9
+ # tag_path - tag path, eg /tag/web/
10
+ #
11
+ # Returns nothing.
12
+ def update_paginate_paths(site, tag_path)
13
+ if @page > 1
14
+ @previous_page_path = tag_path.sub(/(\/)+$/,'') + @previous_page_path
15
+ end
16
+ if @page < @total_pages
17
+ @next_page_path = tag_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_tag(site, num_page, tag_path, paginate_path = site.config['paginate_path'])
29
+ return nil if num_page.nil?
30
+ return tag_path if num_page <= 1
31
+ format = tag_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
@@ -0,0 +1,44 @@
1
+ module Jekyll
2
+ module Paginate
3
+ module Tags
4
+
5
+ class TagPage < Jekyll::Page
6
+ # Attributes for Liquid templates
7
+ ATTRIBUTES_FOR_LIQUID = %w(
8
+ tag
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
+ # tag - The String tag
23
+ def initialize(site, base, tag)
24
+ layout = site.config['paginate_tag_layout'] || 'tag.html'
25
+ super(site, base, '_layouts', layout)
26
+ process('index.html')
27
+
28
+ # Get the tag into layout using page.tag
29
+ @tag = tag
30
+ end
31
+
32
+ # Produce a tag object suitable for Liquid.
33
+ #
34
+ # Returns a String
35
+ def tag
36
+ if @tag.is_a? String
37
+ @tag
38
+ end
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,69 @@
1
+ require 'jekyll'
2
+
3
+ module Jekyll
4
+ module Paginate
5
+ module Tags
6
+
7
+ # Internal requires
8
+ autoload :TagPage, 'jekyll-paginate-tags/tag-page'
9
+ autoload :Pager, 'jekyll-paginate-tags/pager'
10
+
11
+ # Per-tag pagination.
12
+ # Based on jekyll-paginate.
13
+ #
14
+ # paginate_tag_basepath: tag base path - eg, /tag/:name/
15
+ # paginate_path: will be concatenated with paginate_tag - eg /page/:num/
16
+ # paginate_tag_layout: The layout name of the tag layout (default: tags.html)
17
+ class TagPagination < 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_tag_basepath']
27
+ for tag in site.tags.keys
28
+ paginate_tag(site, tag)
29
+ end
30
+ end
31
+ end
32
+
33
+ # Do the blog's posts pagination per tag. Renders the index.html file into paginated
34
+ # directories (see paginate_tag_basepath and paginate_path config) for these tags,
35
+ # e.g.: /tags/my-tag/page2/index.html, /tags/my-tag/page3/index.html, etc.
36
+ #
37
+ # site - The Site.
38
+ # tag - The tag to paginate.
39
+ #
40
+ # Returns nothing.
41
+ def paginate_tag(site, tag)
42
+ # Retrieve posts from that specific tag.
43
+ all_posts = site.site_payload['site']['tags'][tag]
44
+
45
+ # Tag base path
46
+ tag_path = site.config['paginate_tag_basepath']
47
+ tag_path = tag_path.sub(':name', tag.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, tag_path)
57
+
58
+ # Create new page, based on tag layout
59
+ newpage = TagPage.new(site, site.source, tag)
60
+ newpage.pager = pager
61
+ newpage.dir = Pager.paginate_path_c\tag(site, current_num_page, tag_path)
62
+ site.pages << newpage
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-paginate-tags
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Kenta Ng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-04 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.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
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 tag
56
+ email:
57
+ - dev@kentaccn.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/jekyll-paginate-tags.rb
63
+ - lib/jekyll-paginate-tags/pager.rb
64
+ - lib/jekyll-paginate-tags/tag-page.rb
65
+ homepage: https://github.com/kentaccn/jekyll-paginate-tags
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.8
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Generate Pagination for Jekyll tags.
89
+ test_files: []