{% comment %} # ----------------------------------------------------------------------------- # ~/_includes/themes/j1/procedures/components/create_word_cloud.proc # Liquid PROCEDURE to create a word cloud from a list of comma separated # words. # # https://jekyll-one.com # # Copyright (C) 2019 Juergen Adams # # J1 Template is licensed under the MIT License. # See: https://github.com/jekyll-one/j1_template_mde/blob/master/LICENSE # # ----------------------------------------------------------------------------- # Components procedure. Create the HTML code (to be included in a page) for # a word cloud generated from a LIST of comma separated WORDS. All words are # counted against a given SOURCE (how often they are found). # Supported SOURCES are: tags|categories # # If a (second) list of words given by 'skip_words', all words will be # EXCLUDED from the word cloud. # # Usage: # 1) assign the 'source', 'word_list' and 'skip_words' variables # 2) include the create_word_cloud.proc procedure # # Example: # # {% capture create_word_cloud %}themes/{{site.template.name}}/procedures/global/create_word_cloud.proc{% endcapture %} # # {% capture my_site_tag_list %}{% for tag in site.tags %}{{ tag | first }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %} # {% include {{create_word_cloud}} source="tags" word_list=my_site_tag_list %} # # ----------------------------------------------------------------------------- # Test data: # liquid_var: {{ liquid_var | debug }} # # ----------------------------------------------------------------------------- {% endcomment %} {% comment %} Variables ------------------------------------------------------------ {% endcomment %} {% assign word_list = include.word_list %} {% assign source = include.source %} {% assign skip_words = include.skip_words | remove: ' ' %} {% assign skip_word_array = skip_words | split:',' | sort %} {% assign word_array = word_list | split:',' | sort %} {% if source == 'categories' %} {% assign categories = site.categories | sort %} {% endif %} {% assign skip = false %} {% comment %} Liquid procedures ------------------------------------------------------------ {% endcomment %} {% comment %} Main ------------------------------------------------------------ {% endcomment %}
{% unless word_list %} {% assign word_list = 'empty wordlist' %}
Cannot create word cloud. EMPTY or INVALID word cloud specified: {{word_list}}
{% else %}
    {% if source == 'categories' %} {% for tag in word_array %} {% for skip_word in skip_word_array %} {% if tag == skip_word %} {% assign skip = true %} {% else %} {% assign skip = false %} {% endif %} {% endfor %} {% if skip %} {% continue %} {% endif %}
  • {{ tag | capitalize }} {{ site.categories[tag] | size }}
  • {% endfor %} {% elsif source == 'tags' %} {% for tag in word_array %} {% for skip_word in skip_word_array %} {% if skip_word contains tag %} {% assign skip = true %} {% else %} {% assign skip = false %} {% endif %} {% if skip %} {% break %} {% endif %} {% endfor %} {% comment %} {% assign category = tag|first %} {% if category contains 'posts' %} {% assign skip = true %} {% break %} {% else %} {% assign skip = false %} {% endif %} {% endcomment %} {% if skip %} {% continue %} {% endif %}
  • {{ tag }} {{ site.tags[tag] | size }}
  • {% endfor %} {% else %} {% unless source %} {% assign source = 'wrong parameter or missing' %} {% endunless %} Cannot create word cloud. Unknown SOURCE of word cloud specified: {{source}} {% endif %}
{% endunless %}