Skip to content

Commit f6e9a3f

Browse files
committed
fix: the image URL in the SEO-related tags is incomplete (#754)
This issue occurs when setting the `img_path` of the post or the `baseurl` of the site configuration.
1 parent ae2669f commit f6e9a3f

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

_includes/head.html

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,21 @@
2222
{% seo title=false %}
2323
{% endcapture %}
2424

25-
{% if site.img_cdn and seo_tags contains 'og:image' %}
26-
{% assign properties = 'og:image,twitter:image' | split: ',' %}
27-
28-
{% for prop in properties %}
29-
{% if site.img_cdn contains '//' %}
30-
<!-- `site.img_cdn` is a cross-origin URL -->
31-
{% capture target %}<meta property="{{ prop }}" content="{{ site.url }}{% endcapture %}
32-
{% capture replacement %}<meta property="{{ prop }}" content="{{ site.img_cdn }}{% endcapture %}
33-
{% else %}
34-
<!-- `site.img_cdn` is a local file path -->
35-
{% capture target %}<meta property="{{ prop }}" content="{{ site.url }}{{ site.baseurl }}{% endcapture %}
36-
{% assign replacement = target | append: site.img_cdn %}
37-
{% endif %}
38-
39-
{% assign seo_tags = seo_tags | replace: target, replacement %}
25+
{% if page.image.path %}
26+
{% capture target %}"{{ site.url }}{{ page.image.path | relative_url }}"{% endcapture %}
27+
28+
{% if site.img_cdn contains '//' %}
29+
<!-- it's a cross-origin URL -->
30+
{% capture replacement %}"{{ site.img_cdn }}{{ page.img_path }}{{ page.image.path }}"{% endcapture %}
31+
{% else %}
32+
<!-- it's a local file path -->
33+
{%- capture replacement -%}
34+
"{{ site.url }}{{ site.baseurl }}{{ site.img_cdn }}{{ page.img_path }}{{ page.image.path }}"
35+
{%- endcapture -%}
36+
{% endif %}
37+
38+
{% assign seo_tags = seo_tags | replace: target, replacement %}
4039

41-
{% endfor %}
4240
{% endif %}
4341

4442
{{ seo_tags }}

0 commit comments

Comments
 (0)