{% comment %} # ----------------------------------------------------------------------------- # ~/_includes/themes/j1/procedures/layouts/resource_writer.proc # Liquid PROCEDURE to place HTML resources for every LAYOUT # # Product/Info: # 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 # # ----------------------------------------------------------------------------- # Test data: # liquid_var: {{ liquid_var | debug }} # # ----------------------------------------------------------------------------- {% endcomment %} {% comment %} Liquid procedures --------------------------------------------------------------- {% endcomment %} {% capture select_location %}themes/{{site.template.name}}/procedures/global/select_location.proc{% endcapture %} {% comment %} Variables -------------------------------------------------------------------------------- {% endcomment %} {% assign items = include.resources %} {% assign globals = include.globals %} {% assign placement = include.region %} {% assign environment = site.environment %} {% comment %} Main -------------------------------------------------------------------------------- {% endcomment %} {% for global in globals %} {% assign key = global[0] %} {% assign value = global[1] %} {% if key == 'base_path' %} {% assign base_path = value %} {% endif %} {% if key == 'location' %} {% assign location = value %} {% endif %} {% endfor %} {% for resources in items %} {% for resource in resources %} {% for parameters in resource %} {% for parameter in parameters %} {% assign data_type = parameter | is_type %} {% if data_type == 'array' %} {% assign key = parameter[0] %} {% assign value = parameter[1] %} {% if key == 'enabled' %} {% assign enabled = value %} {% endif %} {% if key == 'id' %} {% assign id = value %} {% endif %} {% if key == 'comment' %} {% assign comment = value %} {% endif %} {% if key == 'layout' %} {% assign layouts = value %} {% endif %} {% if key == 'region' %} {% assign region = value %} {% endif %} {% if key == 'required' %} {% assign required = value %} {% endif %} {% if key == 'script_load' %} {% assign script_load = value %} {% endif %} {% if key == 'pass_init_data' %} {% assign pass_init_data = value %} {% endif %} {% if key == 'data' %} {% assign data = value %} {% endif %} {% endif %} {% endfor %} {% endfor %} {% if script_load == 'sync' %} {% assign script_load = '' %} {% endif %} {% if enabled and placement == 'head' %} {% assign layout_valid = false %} {% for layout in layouts %} {% assign layout = layout | downcase %} {% if layout == page.layout or layout == "all" %} {% assign layout_valid = true %} {% endif %} {% endfor %} {% assign resource_valid = false %} {% if required == 'always' %} {% assign resource_valid = true %} {% else %} {% for page_resource in page.resources %} {% if page_resource == id %} {% assign resource_valid = true %} {% endif %} {% endfor %} {% endif %} {% if layout_valid and resource_valid %} {% for data_var in data %} {% assign data_key = data_var[0] %} {% assign data_value = data_var[1] %} {% if data_key == 'files' %} {% for file in data_value %} {% assign splitted_resource = file | split: ":" %} {% assign url_detected = splitted_resource | size %} {% assign splitted_resource = file | split: "." %} {% assign split_count = splitted_resource | size %} {% if split_count > 1 %} {% assign resource_ext = splitted_resource | last %} {% case resource_ext %} {% when 'json' %} {% if url_detected > 1 %} {% else %} {% endif %} {% when 'js' %} {% if url_detected > 1 %} {% else %} {% endif %} {% when 'css' %} {% if url_detected > 1 %} {% else %} {% endif %} {% else %} <--! UNKNOWN resource type detected for: "{{file}}" --> {% endcase %} {% else %} {% if url_detected > 1 %} {% else %} {% endif %} {% endif %} {% endfor %} {% endif %} {% if data_key == 'css' %} {% for locator in data_value %} {% include {{select_location}} location=location locator=locator %} {% assign my_location = {{location_source}} %} {% if environment == 'development' %} {% if location == 'remote' %} {% endif %} {% if location == 'local' %} {% endif %} {% else %} {% if location == 'remote' %} {% endif %} {% if location == 'local' %} {% endif %} {% endif %} {% endfor %} {% endif %} {% if data_key == 'js' %} {% for locator in data_value %} {% include {{select_location}} location=location locator=locator %} {% assign my_location = {{location_source}} %} {% if environment == 'development' %} {% if location == 'remote' %} {% endif %} {% if location == 'local' %} {% endif %} {% else %} {% if location == 'remote' %} {% endif %} {% if location == 'local' %} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endif %} {% endif %} {% endfor %} {% endfor %}