Skip to content

Commit b8d1bcd

Browse files
committed
fix: resume the preview image SEO tag (#529)
Fix #529
1 parent a60a456 commit b8d1bcd

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

_includes/head.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,30 @@
2323

2424
{% endif %}
2525

26-
{% seo title=false %}
26+
{% capture seo_tags %}
27+
{% seo title=false %}
28+
{% endcapture %}
29+
30+
{% if site.img_cdn and seo_tags contains 'og:image' %}
31+
{% assign properties = 'og:image,twitter:image' | split: ',' %}
32+
33+
{% for prop in properties %}
34+
{% if site.img_cdn contains '//' %}
35+
<!-- `site.img_cdn` cross-origin URL -->
36+
{% capture target %}<meta property="{{ prop }}" content="{{ site.url }}{% endcapture %}
37+
{% capture replacement %}<meta property="{{ prop }}" content="{{ site.img_cdn }}{% endcapture %}
38+
{% else %}
39+
<!-- `site.img_cdn` is a local file path -->
40+
{% capture target %}<meta property="{{ prop }}" content="{{ site.url }}{{ site.baseurl }}{% endcapture %}
41+
{% assign replacement = target | append: site.img_cdn %}
42+
{% endif %}
43+
44+
{% assign seo_tags = seo_tags | replace: target, replacement %}
45+
46+
{% endfor %}
47+
{% endif %}
48+
49+
{{ seo_tags }}
2750
2851
<title>
2952
{%- unless page.layout == "home" -%}

_layouts/post.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
{% include lang.html %}
1313

14-
{% if page.image.src %}
14+
{% if page.image.path %}
1515
{% capture bg %}
1616
{% unless page.image.no_bg %}{{ 'bg' }}{% endunless %}
1717
{% endcapture %}
18-
<img src="{{ page.image.src }}" class="preview-img {{ bg | strip }}"
18+
<img src="{{ page.image.path }}" class="preview-img {{ bg | strip }}"
1919
alt="{{ page.image.alt | default: "Preview Image" }}"
2020

2121
{% if page.image.width %}

0 commit comments

Comments
 (0)