fix: resume the preview image SEO tag (#529)

Fix #529
This commit is contained in:
Cotes Chung 2022-03-16 19:43:23 +08:00
parent a60a4562bf
commit b8d1bcd3de
No known key found for this signature in database
GPG key ID: 0D9E54843167A808
2 changed files with 26 additions and 3 deletions

View file

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

View file

@ -11,11 +11,11 @@ tail_includes:
{% include lang.html %} {% include lang.html %}
{% if page.image.src %} {% if page.image.path %}
{% capture bg %} {% capture bg %}
{% unless page.image.no_bg %}{{ 'bg' }}{% endunless %} {% unless page.image.no_bg %}{{ 'bg' }}{% endunless %}
{% endcapture %} {% endcapture %}
<img src="{{ page.image.src }}" class="preview-img {{ bg | strip }}" <img src="{{ page.image.path }}" class="preview-img {{ bg | strip }}"
alt="{{ page.image.alt | default: "Preview Image" }}" alt="{{ page.image.alt | default: "Preview Image" }}"
{% if page.image.width %} {% if page.image.width %}