Skip to content

Commit

Permalink
issue warning for documents missing sort-key
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmaroli committed Sep 2, 2017
1 parent a8afee4 commit 4da1610
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions features/collections.feature
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ Feature: Collections
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
And I should see "Missing sort key 'approx_time'" in the build output
And I should see "Collections: Extending with Plugins, Let's Roll!, Getting Started, Graduation Day, Dive-In and Publish Already!, Tip of the Iceberg" in "_site/index.html"
And I should see "Previous: Extending with Plugins" in "_site/tutorials/lets-roll.html"
And I should see "Next: Getting Started" in "_site/tutorials/lets-roll.html"
Expand Down
7 changes: 7 additions & 0 deletions lib/jekyll/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ def sort_docs_by_key!
# If both documents have the property, sort by that property.
apple_property <=> orange_property
elsif !apple_property.nil? && orange_property.nil?
missing_sort_key_warning(meta_key, orange_document)
-1
elsif apple_property.nil? && !orange_property.nil?
missing_sort_key_warning(meta_key, apple_document)
1
else
# Fall back to Document#<=> if both documents don't have the property.
Expand All @@ -239,6 +241,11 @@ def sort_docs_by_key!
end
# rubocop:enable Metrics/AbcSize

def missing_sort_key_warning(sort_key, document)
Jekyll.logger.warn "Sort warning:",
"Missing sort key '#{sort_key}' in document #{document.relative_path.cyan}"
end

def read_static_file(file_path, full_path)
relative_dir = Jekyll.sanitized_path(
relative_directory,
Expand Down

0 comments on commit 4da1610

Please sign in to comment.