2024-01-10 04:04:27 +03:00
|
|
|
{%- comment -%}
|
2024-04-12 23:34:48 +03:00
|
|
|
Generate media resource final URL based on `site.cdn`, `page.media_subpath`
|
2024-01-10 04:04:27 +03:00
|
|
|
|
|
|
|
Arguments:
|
2024-04-12 23:34:48 +03:00
|
|
|
src - required, basic media resources path
|
|
|
|
subpath - optional, relative path of media resources
|
2024-01-28 00:53:54 +03:00
|
|
|
absolute - optional, boolean, if true, generate absolute URL
|
2024-01-10 04:04:27 +03:00
|
|
|
|
|
|
|
Return:
|
2024-04-12 23:34:48 +03:00
|
|
|
media resources URL
|
2024-01-10 04:04:27 +03:00
|
|
|
{%- endcomment -%}
|
|
|
|
|
|
|
|
{% assign url = include.src %}
|
|
|
|
|
|
|
|
{%- if url -%}
|
2024-01-10 21:11:25 +03:00
|
|
|
{% unless url contains ':' %}
|
2024-04-12 23:34:48 +03:00
|
|
|
{%- comment -%} Add media resources subpath prefix {%- endcomment -%}
|
|
|
|
{% assign url = include.subpath | default: '' | append: '/' | append: url %}
|
2024-01-10 04:04:27 +03:00
|
|
|
|
2024-03-23 21:28:28 +03:00
|
|
|
{%- comment -%} Prepend CND URL {%- endcomment -%}
|
2024-04-12 23:34:48 +03:00
|
|
|
{% if site.cdn %}
|
|
|
|
{% assign url = site.cdn | append: '/' | append: url %}
|
2024-01-28 00:53:54 +03:00
|
|
|
{% endif %}
|
2024-03-23 21:28:28 +03:00
|
|
|
|
|
|
|
{% assign url = url | replace: '///', '/' | replace: '//', '/' | replace: ':/', '://' %}
|
|
|
|
|
|
|
|
{% unless url contains '://' %}
|
|
|
|
{% if include.absolute %}
|
|
|
|
{% assign url = site.url | append: site.baseurl | append: url %}
|
|
|
|
{% else %}
|
|
|
|
{% assign url = site.baseurl | append: url %}
|
|
|
|
{% endif %}
|
|
|
|
{% endunless %}
|
2024-01-10 21:11:25 +03:00
|
|
|
{% endunless %}
|
2024-01-10 04:04:27 +03:00
|
|
|
{%- endif -%}
|
|
|
|
|
|
|
|
{{- url -}}
|