Skip to content

Instantly share code, notes, and snippets.

@pepelsbey
Last active June 28, 2019 12:15
Show Gist options
  • Save pepelsbey/9334494 to your computer and use it in GitHub Desktop.
Save pepelsbey/9334494 to your computer and use it in GitHub Desktop.
Removing duplicates from Liquid array
{% assign array = 'c|c|b|b|a|a' | split: '|' %}
{% assign tags = array[1] %}
{% for item in array %}
{% unless tags contains item %}
{% capture tags %}{{ tags }}|{{ item }}{% endcapture %}
{% endunless %}
{% endfor %}
{{ tags | split: '|' | sort | join: ', ' }}
module Jekyll
module KeepUnique
def keep_unique(input)
input.to_s.split('|').uniq
end
end
end
Liquid::Template.register_filter(Jekyll::KeepUnique)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment