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