Skip to content

Commit

Permalink
fix: resume the preview image SEO tag (cotes2020#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
cotes2020 authored and shihtiy-tw committed Nov 26, 2022
1 parent ad1e5bb commit b61e5d8
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 b61e5d8

Please sign in to comment.