Skip to content

Commit 8de1abd

Browse files
committed
fix: og:image will be incorrect if the image uses a cross-domain URL
1 parent 4b6ccbc commit 8de1abd

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

_includes/head.html

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,25 @@
2424

2525
{% if page.image %}
2626
{% assign img = page.image.path | default: page.image %}
27-
{% assign img_path = page.img_path | append: '/' | append: img | replace: '//', '/' %}
28-
{% capture target %}"{{ img | absolute_url }}"{% endcapture %}
29-
30-
{% if site.img_cdn contains '//' %}
31-
<!-- it's a cross-origin URL -->
32-
{% capture replacement %}"{{ site.img_cdn }}{{ img_path }}"{% endcapture %}
33-
{% else %}
34-
<!-- it's a local file path -->
35-
{%- capture replacement -%}
36-
"{{ site.img_cdn | append: '/' | append: img_path | replace: '//', '/' | absolute_url }}"
37-
{%- endcapture -%}
38-
{% endif %}
3927

40-
{% assign seo_tags = seo_tags | replace: target, replacement %}
28+
{% unless img contains '://' %}
29+
{% assign img_path = page.img_path | append: '/' | append: img | replace: '//', '/' %}
30+
{% capture target %}"{{ img | absolute_url }}"{% endcapture %}
31+
32+
{% if site.img_cdn contains '//' %}
33+
<!-- it's a cross-origin URL -->
34+
{% capture replacement %}"{{ site.img_cdn }}{{ img_path }}"{% endcapture %}
35+
{% else %}
36+
<!-- it's a local file path -->
37+
{%- capture replacement -%}
38+
"{{ site.img_cdn | append: '/' | append: img_path | replace: '//', '/' | absolute_url }}"
39+
{%- endcapture -%}
40+
{% endif %}
41+
42+
{% assign seo_tags = seo_tags | replace: target, replacement %}
43+
44+
{% endunless %}
45+
4146
{% endif %}
4247

4348
{{ seo_tags }}

0 commit comments

Comments
 (0)