From b2d1cb68db659270aac537d2aa8d4b806fa6991d Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 11 Jan 2024 02:11:25 +0800 Subject: [PATCH] fix: `og:image` URL is incorrect (#1468) Introduced by #1463 --- _includes/head.html | 2 +- _includes/img-url.html | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/_includes/head.html b/_includes/head.html index 3885ef2..70a33bd 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -26,7 +26,7 @@ {%- capture old_url -%}{{ src | absolute_url }}{%- endcapture -%} {%- capture new_url -%}{{ img_url }}{%- endcapture -%} - {% assign seo_tags = seo_tags | replace: old, new %} + {% assign seo_tags = seo_tags | replace: old_url, new_url %} {% endunless %} {% elsif site.social_preview_image %} diff --git a/_includes/img-url.html b/_includes/img-url.html index 637029b..44a80af 100644 --- a/_includes/img-url.html +++ b/_includes/img-url.html @@ -12,13 +12,21 @@ {% assign url = include.src %} {%- if url -%} - {%- comment -%} CND URL {%- endcomment -%} - {% assign prefix = site.img_cdn | default: '' | relative_url %} + {% unless url contains ':' %} + {%- comment -%} CND URL {%- endcomment -%} + {% assign prefix = site.img_cdn | default: '' | relative_url %} - {%- comment -%} Add page image path prefix {%- endcomment -%} - {% assign url = include.img_path | default: '' | append: '/' | append: url %} + {%- comment -%} Add page image path prefix {%- endcomment -%} + {% assign url = include.img_path | default: '' | append: '/' | append: url %} - {% assign url = prefix | append: '/' | append: url | replace: '///', '/' | replace: '//', '/' | replace: ':', ':/' %} + {% assign url = prefix + | append: '/' + | append: url + | replace: '///', '/' + | replace: '//', '/' + | replace: ':', ':/' + %} + {% endunless %} {%- endif -%} {{- url -}}