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.
This commit is contained in:
Cotes Chung 2022-11-17 07:31:05 +08:00
parent ae2669fedc
commit f6e9a3fccf
No known key found for this signature in database
GPG key ID: 0D9E54843167A808

View file

@ -22,23 +22,21 @@
{% seo title=false %} {% seo title=false %}
{% endcapture %} {% endcapture %}
{% if site.img_cdn and seo_tags contains 'og:image' %} {% if page.image.path %}
{% assign properties = 'og:image,twitter:image' | split: ',' %} {% capture target %}"{{ site.url }}{{ page.image.path | relative_url }}"{% endcapture %}
{% for prop in properties %}
{% if site.img_cdn contains '//' %} {% if site.img_cdn contains '//' %}
<!-- `site.img_cdn` is a cross-origin URL --> <!-- it's a cross-origin URL -->
{% capture target %}<meta property="{{ prop }}" content="{{ site.url }}{% endcapture %} {% capture replacement %}"{{ site.img_cdn }}{{ page.img_path }}{{ page.image.path }}"{% endcapture %}
{% capture replacement %}<meta property="{{ prop }}" content="{{ site.img_cdn }}{% endcapture %}
{% else %} {% else %}
<!-- `site.img_cdn` is a local file path --> <!-- it's a local file path -->
{% capture target %}<meta property="{{ prop }}" content="{{ site.url }}{{ site.baseurl }}{% endcapture %} {%- capture replacement -%}
{% assign replacement = target | append: site.img_cdn %} "{{ site.url }}{{ site.baseurl }}{{ site.img_cdn }}{{ page.img_path }}{{ page.image.path }}"
{%- endcapture -%}
{% endif %} {% endif %}
{% assign seo_tags = seo_tags | replace: target, replacement %} {% assign seo_tags = seo_tags | replace: target, replacement %}
{% endfor %}
{% endif %} {% endif %}
{{ seo_tags }} {{ seo_tags }}