summaryrefslogtreecommitdiffstats
path: root/blog
diff options
context:
space:
mode:
Diffstat (limited to 'blog')
-rw-r--r--blog/_plugins/multi-paginate.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/blog/_plugins/multi-paginate.rb b/blog/_plugins/multi-paginate.rb
new file mode 100644
index 0000000..9978116
--- /dev/null
+++ b/blog/_plugins/multi-paginate.rb
@@ -0,0 +1,46 @@
+module Jekyll
+ class Paginate < Page
+ attr_accessor :pagination, :page_num
+
+ def initialize(site, pagepath, pagination)
+ super(site, site.source, File.dirname(pagepath), File.basename(pagepath))
+ @pagination = pagination
+ @page_num = @pagination['num']
+
+ self.data['pagination']=pagination
+ self.data.delete "paginate"
+ end
+
+ def url
+ orig = super
+ orig = File.join(orig, @page_num.to_s) if @page_num > 0
+ File.join(orig, 'index.html')
+ end
+ end
+
+ class MultiPaginateGenerator < Generator
+ safe true
+
+ def generate(site)
+ # We're only interested in pages with `paginate`set
+ paginate_pages = site.pages.reject { |page| page.data['paginate'].nil? }
+ paginate_pages.each do |page|
+ posts_per_page = page.data['paginate'].to_i
+ lang = page.data['lang']
+ posts_in_lang = site.posts.docs
+ .reject { |post| post.data['lang'] != lang }
+ .reverse
+
+ num_pages = (posts_in_lang.length.to_f / posts_per_page.to_f).ceil
+ num_pages.times do |i|
+ page_posts = posts_in_lang.slice(i * posts_per_page, posts_per_page)
+ pagination = {
+ 'posts' => page_posts,
+ 'num' => i,
+ }
+ site.pages << Paginate.new(site, page.path, pagination)
+ end
+ end
+ end
+ end
+end