Skip to content

Instantly share code, notes, and snippets.

@lukas-h
Created July 31, 2017 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukas-h/fa47832a53840c468a6f7f4257068e48 to your computer and use it in GitHub Desktop.
Save lukas-h/fa47832a53840c468a6f7f4257068e48 to your computer and use it in GitHub Desktop.
Merge site.categories with site.tags
{% assign all_categories = "" | split:"/" %}
{% assign categories = "" | split:"/" %}
{% for tag in site.categories %}
{% assign all_categories = all_categories | push: tag %}
{% endfor %}
{% for tag in site.tags %}
{% assign all_categories = all_categories | push: tag %}
{% endfor %}
{% for category1 in all_categories %}
{% assign multiple = 0 %}
{% assign multiple_assigned == false %}
{% assign is_already_in_results = false %}
{% for result_cat in categories %}
{% if result_cat[0] == category1[0] %}
{% assign is_already_in_results = true %}
{% endif %}
{% endfor %}
{% if is_already_in_results == false %}
{% for category2 in all_categories %}
{% if category1[0] == category2[0] %}
{% if multiple == 1 %}
{% for page_with_tag in category2[1] %}
{% assign page_already_exists = false %}
{% for page_in_cat1 in category1[1] %}
{% if page_in_cat1.path == page_with_tag.path %}
{% assign page_already_exists = true %}
{% endif %}
{% endfor %}
{% if page_already_exists == false %}
{% assign category1[1] = category1[1] | push: page_with_tag %}
{% endif %}
{% endfor %}
{% assign categories = categories | push: category1 %}
{% assign multiple_assigned = true %}
{% assign all_categories = all_categories | shift %}
{% break %}
{% else %}
{% assign multiple = 1 %}
{% endif %}
{% endif %}
{% endfor %}
{% if multiple_assigned != true %}
{% assign categories = categories | push: category1 %}
{% endif %}
{% endif %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment