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 %}
|
||||
{% endcapture %}
|
||||
|
||||
{% if page.image.path %}
|
||||
{% capture target %}"{{ site.url }}{{ page.image.path | relative_url }}"{% endcapture %}
|
||||
{% if page.image %}
|
||||
{% 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 '//' %}
|
||||
<!-- 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 %}
|
||||
<!-- it's a local file path -->
|
||||
{%- 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 -%}
|
||||
{% endif %}
|
||||
|
||||
{% assign seo_tags = seo_tags | replace: target, replacement %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{{ seo_tags }}
|
||||
|
|
|
@ -107,13 +107,7 @@
|
|||
|
||||
<!-- Add image path -->
|
||||
{% if page.img_path %}
|
||||
{% assign _path = page.img_path %}
|
||||
{% assign last_char = _path | slice: -1 %}
|
||||
|
||||
{% unless last_char == '/' %}
|
||||
{% assign _path = _path | append: '/' %}
|
||||
{% endunless %}
|
||||
|
||||
{% assign _path = page.img_path | append: '/' | replace: '//', '/' %}
|
||||
{% assign _src_prefix = _src_prefix | append: _path %}
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -26,13 +26,13 @@ tail_includes:
|
|||
</span>
|
||||
{% endif %}
|
||||
|
||||
{% if page.image.path %}
|
||||
{% if page.image %}
|
||||
{% capture bg %}
|
||||
{% unless page.image.no_bg %}{{ 'bg' }}{% endunless %}
|
||||
{% endcapture %}
|
||||
|
||||
<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" }}"
|
||||
|
||||
{% if page.image.width %}
|
||||
|
|
Loading…
Reference in a new issue