File tree Expand file tree Collapse file tree 3 files changed +147
-0
lines changed
Expand file tree Collapse file tree 3 files changed +147
-0
lines changed Original file line number Diff line number Diff line change 1+ module Jekyll
2+ module Paginate
3+ module CategoryPager
4+ VERSION = "0.1.2"
5+
6+ class Pagination < Generator
7+ safe true
8+ priority :lowest
9+
10+ def generate ( site )
11+ if Paginate ::Pager . pagination_enabled? ( site )
12+ site . categories . each do |category , posts |
13+ total = Paginate ::Pager . calculate_pages ( posts , site . config [ 'paginate' ] )
14+ ( 1 ..total ) . each do |page |
15+ site . pages << IndexPage . new ( site , category , page )
16+ end
17+ end
18+ end
19+ end
20+ end
21+
22+ class IndexPage < Page
23+ def initialize ( site , category , num_page )
24+ @site = site
25+ @base = site . source
26+
27+ @dir = File . join ( category )
28+
29+ if num_page ==1
30+ @name = 'index.html'
31+ else
32+ @name = "/index_#{ num_page } .html"
33+ end
34+ self . process ( @name )
35+
36+ category_layout = site . config [ 'category_layout' ]
37+ self . read_yaml ( @base , category_layout )
38+
39+ self . data . merge! (
40+ 'title' => category ,
41+ 'category' => category ,
42+ 'paginator' => Paginate ::Pager . new ( site , num_page , site . categories [ category ] )
43+ )
44+ end
45+
46+ def template
47+ '/:path/:basename:output_ext'
48+ end
49+ end
50+
51+ end
52+ end
53+ end
Original file line number Diff line number Diff line change 1+ module Jekyll
2+ module Paginate
3+ module IndexPager
4+ VERSION = "0.1.2"
5+
6+ class Pagination < Generator
7+ safe true
8+ priority :lowest
9+
10+ def generate ( site )
11+ if Paginate ::Pager . pagination_enabled? ( site )
12+ #revert posts
13+ posts_len = site . posts . docs . size
14+ revert_posts = Array . new
15+ ( 0 ..( posts_len -1 ) ) . each do |id |
16+ revert_posts [ ( posts_len -1 ) -id ] = site . posts . docs [ id ] ;
17+ end
18+ #paginate
19+ total = Paginate ::Pager . calculate_pages ( site . posts , site . config [ 'paginate' ] )
20+ ( 1 ..total ) . each do |page |
21+ site . pages << IndexPage . new ( site , page , revert_posts , total )
22+ end
23+ end
24+ end
25+ end
26+
27+ class IndexPage < Page
28+ def initialize ( site , num_page , all_posts , total_pages )
29+ @site = site
30+ @base = site . source
31+ @dir = File . join ( '/' )
32+
33+ if num_page ==1
34+ @name = 'index.html'
35+ else
36+ @name = "index_#{ num_page } .html"
37+ end
38+
39+ self . process ( @name )
40+
41+ index_layout = site . config [ 'index_layout' ]
42+ self . read_yaml ( @base , index_layout )
43+
44+ self . data . merge! (
45+ 'category' => 'index' ,
46+ 'paginator' => Paginate ::Pager . new ( site , num_page , all_posts , total_pages )
47+ )
48+ end
49+
50+ def template
51+ '/:basename:output_ext'
52+ end
53+ end
54+
55+ end
56+ end
57+ end
58+
Original file line number Diff line number Diff line change 1+ module Jekyll
2+ module Tags
3+ VERSION = "0.0.1"
4+
5+ class TagGenerator < Generator
6+ safe true
7+ priority :lowest
8+
9+ def generate ( site )
10+ for tag in site . tags
11+ site . pages << IndexPage . new ( site , tag [ 0 ] , tag [ 1 ] ) ;
12+ end
13+ end
14+
15+ end
16+
17+ class IndexPage < Page
18+ def initialize ( site , tag , all_posts )
19+ @site = site
20+ @base = site . source
21+ @dir = File . join ( '/tag' )
22+ @name = "#{ tag } .html"
23+ self . process ( @name )
24+
25+ tag_layout = site . config [ 'tag_layout' ]
26+ self . read_yaml ( @base , tag_layout )
27+ self . data [ 'posts' ] = all_posts
28+ self . data [ 'title' ] = tag
29+ self . data [ 'url' ] = "#{ @dir } /#{ @name } " #设置了无效,好奇怪
30+
31+ end
32+ end
33+
34+ end
35+ end
36+
You can’t perform that action at this time.
0 commit comments