fix: correct the Twitter Card in social share preview (#1498)
--------- Co-authored-by: Cotes Chung <11371340+cotes2020@users.noreply.github.com>
This commit is contained in:
parent
1127c43823
commit
74f16623c9
2 changed files with 20 additions and 8 deletions
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
{% unless src contains '://' %}
|
{% unless src contains '://' %}
|
||||||
{%- capture img_url -%}
|
{%- capture img_url -%}
|
||||||
{% include img-url.html src=src img_path=page.img_path %}
|
{% include img-url.html src=src img_path=page.img_path absolute=true %}
|
||||||
{%- endcapture -%}
|
{%- endcapture -%}
|
||||||
|
|
||||||
{%- capture old_url -%}{{ src | absolute_url }}{%- endcapture -%}
|
{%- capture old_url -%}{{ src | absolute_url }}{%- endcapture -%}
|
||||||
|
@ -31,15 +31,20 @@
|
||||||
|
|
||||||
{% elsif site.social_preview_image %}
|
{% elsif site.social_preview_image %}
|
||||||
{%- capture img_url -%}
|
{%- capture img_url -%}
|
||||||
{% include img-url.html src=site.social_preview_image %}
|
{% include img-url.html src=site.social_preview_image absolute=true %}
|
||||||
{%- endcapture -%}
|
{%- endcapture -%}
|
||||||
|
|
||||||
{%- capture og_image -%}
|
{%- capture og_image -%}
|
||||||
<meta property="og:image" content="{{ img_url }}" />
|
<meta property="og:image" content="{{ img_url }}" />
|
||||||
{%- endcapture -%}
|
{%- endcapture -%}
|
||||||
|
|
||||||
{% assign old_meta_clip = '<meta name="twitter:card"' %}
|
{%- capture twitter_image -%}
|
||||||
{% assign new_meta_clip = og_image | append: old_meta_clip %}
|
<meta property="twitter:card" content="summary_large_image" />
|
||||||
|
<meta property="twitter:image" content="{{ img_url }}" />
|
||||||
|
{%- endcapture -%}
|
||||||
|
|
||||||
|
{% assign old_meta_clip = '<meta name="twitter:card" content="summary" />' %}
|
||||||
|
{% assign new_meta_clip = og_image | append: twitter_image %}
|
||||||
{% assign seo_tags = seo_tags | replace: old_meta_clip, new_meta_clip %}
|
{% assign seo_tags = seo_tags | replace: old_meta_clip, new_meta_clip %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
Generate image final URL based on `site.img_cdn`, `page.img_path`
|
Generate image final URL based on `site.img_cdn`, `page.img_path`
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
src - basic image path, required
|
src - required, basic image path
|
||||||
img_path - relative path of image, optional
|
img_path - optional, relative path of image
|
||||||
|
absolute - optional, boolean, if true, generate absolute URL
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
image URL
|
image URL
|
||||||
|
@ -14,7 +15,7 @@
|
||||||
{%- if url -%}
|
{%- if url -%}
|
||||||
{% unless url contains ':' %}
|
{% unless url contains ':' %}
|
||||||
{%- comment -%} CND URL {%- endcomment -%}
|
{%- comment -%} CND URL {%- endcomment -%}
|
||||||
{% assign prefix = site.img_cdn | default: '' | relative_url %}
|
{% assign prefix = site.img_cdn | default: '' %}
|
||||||
|
|
||||||
{%- comment -%} Add page image path prefix {%- endcomment -%}
|
{%- comment -%} Add page image path prefix {%- endcomment -%}
|
||||||
{% assign url = include.img_path | default: '' | append: '/' | append: url %}
|
{% assign url = include.img_path | default: '' | append: '/' | append: url %}
|
||||||
|
@ -26,6 +27,12 @@
|
||||||
| replace: '//', '/'
|
| replace: '//', '/'
|
||||||
| replace: ':', ':/'
|
| replace: ':', ':/'
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
{% if include.absolute %}
|
||||||
|
{% assign url = url | absolute_url %}
|
||||||
|
{% else %}
|
||||||
|
{% assign url = url | relative_url %}
|
||||||
|
{% endif %}
|
||||||
{% endunless %}
|
{% endunless %}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue