Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Jekyll::Filters#item_property #7696

Merged
merged 4 commits into from Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Expand Up @@ -79,6 +79,8 @@ Metrics/MethodLength:
Severity: error
Metrics/ModuleLength:
Max: 240
Exclude:
- lib/jekyll/filters.rb
Metrics/ParameterLists:
Max: 4
Metrics/PerceivedComplexity:
Expand Down
27 changes: 18 additions & 9 deletions lib/jekyll/filters.rb
Expand Up @@ -356,15 +356,24 @@ def item_property(item, property)
@item_property_cache ||= {}
@item_property_cache[property] ||= {}
@item_property_cache[property][item] ||= begin
if item.respond_to?(:to_liquid)
property.to_s.split(".").reduce(item.to_liquid) do |subvalue, attribute|
parse_sort_input(subvalue[attribute])
end
elsif item.respond_to?(:data)
parse_sort_input(item.data[property.to_s])
else
parse_sort_input(item[property.to_s])
end
property = property.to_s
property = if item.respond_to?(:to_liquid)
read_liquid_attribute(item.to_liquid, property)
elsif item.respond_to?(:data)
item.data[property]
else
item[property]
end

parse_sort_input(property)
end
end

def read_liquid_attribute(liquid_data, property)
return liquid_data[property] unless property.include?(".")

property.split(".").reduce(liquid_data) do |data, key|
data.respond_to?(:[]) && data[key]
end
end

Expand Down