{% comment %} # ----------------------------------------------------------------------------- # ~/_includes/themes/j1/procedures/layouts/resource_writer.proc # Liquid PROCEDURE to place HTML resources for every LAYOUT # # Product/Info: # https://jekyll.one # # Copyright (C) 2023, 2024 Juergen Adams # # J1 Template is licensed under the MIT License. # See: https://github.com/jekyll-one-org/j1-template/blob/main/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 environment = site.environment %} {% assign placement = include.region %} {% assign resource_globals = include.global %} {% assign resource_settings = include.resource %} {% comment %} helpers -------------------------------------------------------------------------------- {% endcomment %} {% assign is_placed = false %} {% if page.debug %} {% endif %} {% comment %} main -------------------------------------------------------------------------------- {% endcomment %} {% for global in resource_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 %} {% if page.debug %} {% endif %} {% comment %} place resource ENABLED -------------------------------------------------------------------------------- {% endcomment %} {% if resource_settings.enabled %} {% if resource_settings.script_load == 'sync' %} {% assign script_load = '' %} {% else %} {% assign script_load = resource_settings.script_load %} {% endif %} {% assign resource_region = resource_settings.region %} {% comment %} place resource for theregion configured (resources.yml) if placement == 'head' or placement == 'body' -------------------------------------------------------------------------------- {% endcomment %} {% if placement == resource_region %} {% assign layout_valid = false %} {% for layout in resource_settings.layout %} {% assign layout = layout|downcase %} {% if layout == page.layout or layout == 'all' %} {% assign layout_valid = true %} {% assign layout = page.layout|downcase %} {% endif %} {% endfor %} {% assign resource_valid = false %} {% if resource_settings.required == 'always' %} {% assign resource_valid = true %} {% else %} {% for resource in page.resources %} {% if resource == resource_settings.id %} {% assign resource_valid = true %} {% endif %} {% endfor %} {% endif %} {% comment %} resource placement ------------------------------------------------------------------------------ {% endcomment %} {% if layout_valid and resource_valid and is_placed == false %} {% comment %} process all data keys ---------------------------------------------------------------------------- {% endcomment %} {% for data_var in resource_settings.data %} {% assign data_key = data_var[0] %} {% assign data_value = data_var[1] %} {% if page.debug %} {% endif %} {% if page.debug %} {% endif %} {% comment %} process data key of type 'files' -------------------------------------------------------------------------- {% endcomment %} {% if data_key == 'files' and layout_valid %} {% 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 %} {% comment %} process data key of type 'css' -------------------------------------------------------------------------- {% endcomment %} {% if data_key == 'css' and layout_valid %} {% 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 %} {% comment %} process data key of type 'js' -------------------------------------------------------------------------- {% endcomment %} {% if data_key == 'js' and layout_valid %} {% 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 %} {% comment %} END process all data keys ---------------------------------------------------------------------------- {% endcomment %} {% assign is_placed = true %} {% endif %} {% endif %} {% endif %}