Skip to content

Commit

Permalink
reduce the verbosity of pagination logging [again] (#180)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
mohkale and sverrirs authored May 2, 2021
1 parent 559ac09 commit e4e1d01
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README-AUTOPAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ autopages:
# Optional, the permalink for the pagination page (:cat is replaced),
# the pagination permalink path is then appended to this permalink structure
permalink: '/category/:cat'
# Optional, when true logging related to category pages will be supressed.
silent: false
slugify:
mode: 'default' # :cat is slugified. Modes: default, raw, pretty, ascii, latin
case: false # Whether to replace all uppercase letters with their lowercase counterparts
Expand All @@ -52,6 +54,7 @@ autopages:
- 'autopage_collection.html'
title: 'Posts in collection :coll' # :coll is replaced by the collection name
permalink: '/collection/:coll'
silent: false
slugify:
mode: 'default' # :coll is slugified.
case: false
Expand All @@ -62,6 +65,7 @@ autopages:
- 'autopage_tags.html'
title: 'Posts tagged with :tag' # :tag is replaced by the tag name
permalink: '/tag/:tag'
silent: false
slugify:
mode: 'default' # :tag is slugified.
case: false
Expand Down
28 changes: 24 additions & 4 deletions lib/jekyll-paginate-v2/autopages/autoPages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def self.create_autopages(site)
return
end

autopages_log(autopage_config, 'tags', 'categories', 'collections')

# TODO: Should I detect here and disable if we're running the legacy paginate code???!

# Simply gather all documents across all pages/posts/collections that we have
Expand Down Expand Up @@ -55,8 +57,6 @@ def self.autopage_create(autopage_config, pagination_config, posts_to_use, confi
if !autopage_config[configkey_name].nil?
ap_sub_config = autopage_config[configkey_name]
if ap_sub_config ['enabled']
Jekyll.logger.info "AutoPages:","Generating #{configkey_name} pages"

# Roll through all documents in the posts collection and extract the tags
index_keys = Utils.ap_index_posts_by(posts_to_use, indexkey_name) # Cannot use just the posts here, must use all things.. posts, collections...

Expand All @@ -67,11 +67,31 @@ def self.autopage_create(autopage_config, pagination_config, posts_to_use, confi
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
end
end
else
Jekyll.logger.info "AutoPages:","#{configkey_name} pages are disabled/not configured in site.config."
end
end
end

def self.autopages_log(config, *config_keys)
enabled, disabled = [], []
config_keys.each do |key|
key_config = config[key] # config for key
next if config.nil? || key_config['silent']

(key_config['enabled'] ? enabled : disabled) << key
end

Jekyll.logger.info("AutoPages:","Generating pages for #{_to_sentence(enabled)}") unless enabled.empty?
Jekyll.logger.info("AutoPages:","#{_to_sentence(disabled)} pages are disabled/not configured in site.config") unless disabled.empty?
end

def self._to_sentence(array)
if array.empty?
""
elsif array.length == 1
array[0].to_s
else
array[0..-2].join(", ") + " & " + array.last
end
end
end # module PaginateV2
end # module Jekyll

0 comments on commit e4e1d01

Please sign in to comment.