refactor: enhance the setting of preview image path
This commit is contained in:
parent
f6e9a3fccf
commit
da7d7e25b6
3 changed files with 9 additions and 14 deletions
|
@ -22,21 +22,22 @@
|
||||||
{% seo title=false %}
|
{% seo title=false %}
|
||||||
{% endcapture %}
|
{% endcapture %}
|
||||||
|
|
||||||
{% if page.image.path %}
|
{% if page.image %}
|
||||||
{% capture target %}"{{ site.url }}{{ page.image.path | relative_url }}"{% endcapture %}
|
{% assign img = page.image.path | default: page.image %}
|
||||||
|
{% assign img_path = page.img_path | append: '/' | append: img | replace: '//', '/' %}
|
||||||
|
{% capture target %}"{{ img | absolute_url }}"{% endcapture %}
|
||||||
|
|
||||||
{% if site.img_cdn contains '//' %}
|
{% if site.img_cdn contains '//' %}
|
||||||
<!-- it's a cross-origin URL -->
|
<!-- it's a cross-origin URL -->
|
||||||
{% capture replacement %}"{{ site.img_cdn }}{{ page.img_path }}{{ page.image.path }}"{% endcapture %}
|
{% capture replacement %}"{{ site.img_cdn }}{{ img_path }}"{% endcapture %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<!-- it's a local file path -->
|
<!-- it's a local file path -->
|
||||||
{%- capture replacement -%}
|
{%- capture replacement -%}
|
||||||
"{{ site.url }}{{ site.baseurl }}{{ site.img_cdn }}{{ page.img_path }}{{ page.image.path }}"
|
"{{ site.img_cdn | append: '/' | append: img_path | replace: '//', '/' | absolute_url }}"
|
||||||
{%- endcapture -%}
|
{%- endcapture -%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% assign seo_tags = seo_tags | replace: target, replacement %}
|
{% assign seo_tags = seo_tags | replace: target, replacement %}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{{ seo_tags }}
|
{{ seo_tags }}
|
||||||
|
|
|
@ -107,13 +107,7 @@
|
||||||
|
|
||||||
<!-- Add image path -->
|
<!-- Add image path -->
|
||||||
{% if page.img_path %}
|
{% if page.img_path %}
|
||||||
{% assign _path = page.img_path %}
|
{% assign _path = page.img_path | append: '/' | replace: '//', '/' %}
|
||||||
{% assign last_char = _path | slice: -1 %}
|
|
||||||
|
|
||||||
{% unless last_char == '/' %}
|
|
||||||
{% assign _path = _path | append: '/' %}
|
|
||||||
{% endunless %}
|
|
||||||
|
|
||||||
{% assign _src_prefix = _src_prefix | append: _path %}
|
{% assign _src_prefix = _src_prefix | append: _path %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,13 @@ tail_includes:
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if page.image.path %}
|
{% if page.image %}
|
||||||
{% capture bg %}
|
{% capture bg %}
|
||||||
{% unless page.image.no_bg %}{{ 'bg' }}{% endunless %}
|
{% unless page.image.no_bg %}{{ 'bg' }}{% endunless %}
|
||||||
{% endcapture %}
|
{% endcapture %}
|
||||||
|
|
||||||
<div class="mt-3 mb-3">
|
<div class="mt-3 mb-3">
|
||||||
<img src="{{ page.image.path }}" class="preview-img {{ bg | strip }}"
|
<img src="{{ page.image.path | default: page.image }}" class="preview-img {{ bg | strip }}"
|
||||||
alt="{{ page.image.alt | default: "Preview Image" }}"
|
alt="{{ page.image.alt | default: "Preview Image" }}"
|
||||||
|
|
||||||
{% if page.image.width %}
|
{% if page.image.width %}
|
||||||
|
|
Loading…
Reference in a new issue