-
Notifications
You must be signed in to change notification settings - Fork 2
/
paginate_archive.rb
53 lines (50 loc) · 1.57 KB
/
paginate_archive.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true
return if ENV['JEKYLL_NO_ARCHIVE']
module Jekyll::UlyssesZhan
end
module Jekyll
class UlyssesZhan::ArchivePaginationGenerator < Generator
LOG = false
safe true
priority :lowest
def generate site
@site = site
@config = Jekyll::Utils.deep_merge_hashes Jekyll::PaginateV2::Generator::DEFAULT, site.config['pagination'] || {}
@site.config['archives'].each do |archive|
@archive = archive
run_pagination_model
end
end
def log message, type = 'info'
case type
when 'debug'
Jekyll.logger.debug 'Archive pagination:', message
when 'error'
Jekyll.logger.error 'Archive pagination:', message
when 'warn'
Jekyll.logger.warn 'Archive pagination:', message
else
Jekyll.logger.info 'Archive pagination:', message
end if LOG
end
def collection_by_name collection_name
@archive.posts
end
def page_add new_page
@site.pages.push new_page
new_page
end
def page_remove page_to_remove
@site.pages.delete page_to_remove
end
def run_pagination_model
@config['permalink'] = File.join @archive.url, @site.config['pagination']['permalink']
@archive.data['pagination'] = {'enabled' => true}
@archive.data['date'] = @archive.date
model = Jekyll::PaginateV2::Generator::PaginationModel.new method(:log), method(:page_add), method(:page_remove), method(:collection_by_name)
count = model.run @config, [@archive], @archive.title
Jekyll.logger.info "Archive pagination:", "Complete #{count} pages for #{@archive.title} #{@archive.date}" if LOG
@archive.data.delete 'pagination'
end
end
end