Skip to content

Commit

Permalink
fix: resume the preview image SEO tag (#529)
Browse files Browse the repository at this point in the history
Fix #529
  • Loading branch information
cotes2020 committed Mar 16, 2022
1 parent a60a456 commit b8d1bcd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 24 additions & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,30 @@

{% 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>
{%- unless page.layout == "home" -%}
Expand Down
4 changes: 2 additions & 2 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

{% include lang.html %}

{% if page.image.src %}
{% if page.image.path %}
{% capture bg %}
{% unless page.image.no_bg %}{{ 'bg' }}{% endunless %}
{% 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" }}"

{% if page.image.width %}
Expand Down

0 comments on commit b8d1bcd

Please sign in to comment.