Skip to content

Commit e4e1d01

Browse files
mohkalesverrirs
andauthored
reduce the verbosity of pagination logging [again] (#180)
* autoPages.rb (restructure): logging to minimise output * autoPages.rb (config): add option to silence logging if users don't want to autopage generate tags, then don't keep telling them it hasn't been configured :P * autopages.md (update): add example for the 'silent' option Co-authored-by: Sverrir Sigmundarson <[email protected]>
1 parent 559ac09 commit e4e1d01

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

README-AUTOPAGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ autopages:
4242
# Optional, the permalink for the pagination page (:cat is replaced),
4343
# the pagination permalink path is then appended to this permalink structure
4444
permalink: '/category/:cat'
45+
# Optional, when true logging related to category pages will be supressed.
46+
silent: false
4547
slugify:
4648
mode: 'default' # :cat is slugified. Modes: default, raw, pretty, ascii, latin
4749
case: false # Whether to replace all uppercase letters with their lowercase counterparts
@@ -52,6 +54,7 @@ autopages:
5254
- 'autopage_collection.html'
5355
title: 'Posts in collection :coll' # :coll is replaced by the collection name
5456
permalink: '/collection/:coll'
57+
silent: false
5558
slugify:
5659
mode: 'default' # :coll is slugified.
5760
case: false
@@ -62,6 +65,7 @@ autopages:
6265
- 'autopage_tags.html'
6366
title: 'Posts tagged with :tag' # :tag is replaced by the tag name
6467
permalink: '/tag/:tag'
68+
silent: false
6569
slugify:
6670
mode: 'default' # :tag is slugified.
6771
case: false

lib/jekyll-paginate-v2/autopages/autoPages.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def self.create_autopages(site)
1616
return
1717
end
1818

19+
autopages_log(autopage_config, 'tags', 'categories', 'collections')
20+
1921
# TODO: Should I detect here and disable if we're running the legacy paginate code???!
2022

2123
# Simply gather all documents across all pages/posts/collections that we have
@@ -55,8 +57,6 @@ def self.autopage_create(autopage_config, pagination_config, posts_to_use, confi
5557
if !autopage_config[configkey_name].nil?
5658
ap_sub_config = autopage_config[configkey_name]
5759
if ap_sub_config ['enabled']
58-
Jekyll.logger.info "AutoPages:","Generating #{configkey_name} pages"
59-
6060
# Roll through all documents in the posts collection and extract the tags
6161
index_keys = Utils.ap_index_posts_by(posts_to_use, indexkey_name) # Cannot use just the posts here, must use all things.. posts, collections...
6262

@@ -67,11 +67,31 @@ def self.autopage_create(autopage_config, pagination_config, posts_to_use, confi
6767
createpage_lambda.call(ap_sub_config, pagination_config, layout_name, index_key, value[-1]) # the last item in the value array will be the display name
6868
end
6969
end
70-
else
71-
Jekyll.logger.info "AutoPages:","#{configkey_name} pages are disabled/not configured in site.config."
7270
end
7371
end
7472
end
7573

74+
def self.autopages_log(config, *config_keys)
75+
enabled, disabled = [], []
76+
config_keys.each do |key|
77+
key_config = config[key] # config for key
78+
next if config.nil? || key_config['silent']
79+
80+
(key_config['enabled'] ? enabled : disabled) << key
81+
end
82+
83+
Jekyll.logger.info("AutoPages:","Generating pages for #{_to_sentence(enabled)}") unless enabled.empty?
84+
Jekyll.logger.info("AutoPages:","#{_to_sentence(disabled)} pages are disabled/not configured in site.config") unless disabled.empty?
85+
end
86+
87+
def self._to_sentence(array)
88+
if array.empty?
89+
""
90+
elsif array.length == 1
91+
array[0].to_s
92+
else
93+
array[0..-2].join(", ") + " & " + array.last
94+
end
95+
end
7696
end # module PaginateV2
7797
end # module Jekyll

0 commit comments

Comments
 (0)