From 8de1abda6be3633982392178731431b0ddb1b52b Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 15 Dec 2022 22:55:52 +0800 Subject: [PATCH] fix: `og:image` will be incorrect if the image uses a cross-domain URL --- _includes/head.html | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/_includes/head.html b/_includes/head.html index 03ab48f..e2f6336 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -24,20 +24,25 @@ {% 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 '//' %} - - {% capture replacement %}"{{ site.img_cdn }}{{ img_path }}"{% endcapture %} - {% else %} - - {%- capture replacement -%} - "{{ site.img_cdn | append: '/' | append: img_path | replace: '//', '/' | absolute_url }}" - {%- endcapture -%} - {% endif %} + {% unless img contains '://' %} + {% assign img_path = page.img_path | append: '/' | append: img | replace: '//', '/' %} + {% capture target %}"{{ img | absolute_url }}"{% endcapture %} + + {% if site.img_cdn contains '//' %} + + {% capture replacement %}"{{ site.img_cdn }}{{ img_path }}"{% endcapture %} + {% else %} + + {%- 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 %} {{ seo_tags }}