fix: og:image will be incorrect if the image uses a cross-domain URL

This commit is contained in:
Cotes Chung 2022-12-15 22:55:52 +08:00
parent 4b6ccbcbcc
commit 8de1abda6b
No known key found for this signature in database
GPG key ID: 0D9E54843167A808

View file

@ -24,20 +24,25 @@
{% if page.image %} {% if page.image %}
{% assign img = page.image.path | default: 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 '//' %} {% unless img contains '://' %}
<!-- it's a cross-origin URL --> {% assign img_path = page.img_path | append: '/' | append: img | replace: '//', '/' %}
{% capture replacement %}"{{ site.img_cdn }}{{ img_path }}"{% endcapture %} {% capture target %}"{{ img | absolute_url }}"{% endcapture %}
{% else %}
<!-- it's a local file path --> {% if site.img_cdn contains '//' %}
{%- capture replacement -%} <!-- it's a cross-origin URL -->
"{{ site.img_cdn | append: '/' | append: img_path | replace: '//', '/' | absolute_url }}" {% capture replacement %}"{{ site.img_cdn }}{{ img_path }}"{% endcapture %}
{%- endcapture -%} {% else %}
{% endif %} <!-- it's a local file path -->
{%- capture replacement -%}
"{{ site.img_cdn | append: '/' | append: img_path | replace: '//', '/' | absolute_url }}"
{%- endcapture -%}
{% endif %}
{% assign seo_tags = seo_tags | replace: target, replacement %}
{% endunless %}
{% assign seo_tags = seo_tags | replace: target, replacement %}
{% endif %} {% endif %}
{{ seo_tags }} {{ seo_tags }}