31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/jekyll/multi/paginate/pagination.rb', line 31
def generate(site)
site.pages.each do |page|
if page.data.has_key?"paginate"
file = page.url
nametofolderpath = file.sub(File.extname(file),"")
if site.permalink_style=="pretty"
pagepath = file.sub(File.extname(file),"")
else
pagepath = File.dirname(file)
end
postmax = page.data['paginate']
onlykey = page.data['paginate_onlykey'] || "all"
dir = site.config['page_path'] || nametofolderpath+"/page:num"
if !dir.include?':num'
dir+=":num"
end
oncatpost = []
postlen = 0
site.posts.docs.each do |post|
if (post.data[onlykey]==page.data[onlykey] || onlykey=="all") && onlykey!=""
oncatpost << post
postlen+=1
end
end
toloop = postlen.to_f/postmax.to_f
for i in 1..toloop.ceil
posts = oncatpost[(i-1)*postmax,postmax]
ndir = toPagePath(dir, i)
pagepaths = []
[*1..toloop.ceil].each do |x|
pagepaths.push(toPagePath(dir, x))
end
instance = {
"nums" => [*1..toloop.ceil],
"posts" => posts,
"paths" => pagepaths,
"paginate_num" => toloop.ceil,
"paginate_path" => "/"+dir+"/".gsub("//","/"),
"total_post" => postlen,
"current_num" => i,
"total_page_num" => toloop.ceil,
"prev_path" => ((i-1)!=0)? toPagePath(dir, i-1):nil,
"next_path" => ((i+1)<=toloop.ceil)? toPagePath(dir, i+1):nil,
"prev_num" => ((i-1)!=0)? i-1:nil,
"next_num" => ((i+1)<=toloop.ceil)? i+1:nil,
}
if i==1
site.pages << MultiPaginate.new(site, site.source, pagepath, page.path, false, instance)
if !(site.permalink_style.downcase=="pretty")
site.pages << MultiPaginate.new(site, site.source, nametofolderpath, page.path, true, instance)
end
end
site.pages << MultiPaginate.new(site, site.source, ndir, page.path, true, instance)
end
end
end
end
|