Files
bqkc/.github/_plugins/array_count_uniq.rb
Nasir Anthony Montalvo 0a854da998 reconnect
2026-01-26 02:25:43 -06:00

14 lines
458 B
Ruby

# use like {{ myarray | array_count_uniq }}
# where myarray is a liquid array
# returns an array of the unique values + counts
# evan will 2018 for CollectionBuilder project
module Jekyll
module ArrayCountUniq
def array_count_uniq(input)
clean = input.compact.collect(&:strip).reject(&:empty?)
clean.uniq.map { |x| [x, clean.count(x)] }.sort_by {|k, v| -v}.to_h
end
end
end
Liquid::Template.register_filter(Jekyll::ArrayCountUniq)