diff --git a/_config.yml b/_config.yml index 05044ca..4ab1726 100644 --- a/_config.yml +++ b/_config.yml @@ -75,6 +75,10 @@ img_cdn: "https://chirpy-img.netlify.app" # the avatar on sidebar, support local or CORS resources avatar: "/commons/avatar.jpg" +# The URL of the site-wide social preview image used in SEO `og:image` meta tag. +# It can be overridden by a customized `page.image` in front matter. +social_preview_image: # string, local or CORS resources + # boolean type, the global switch for TOC in posts. toc: true diff --git a/_includes/head.html b/_includes/head.html index fb12d99..3885ef2 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -1,5 +1,3 @@ - -
@@ -11,29 +9,38 @@ content="width=device-width, user-scalable=no initial-scale=1, shrink-to-fit=no, viewport-fit=cover" > - {% capture seo_tags %} + {%- capture seo_tags -%} {% seo title=false %} - {% endcapture %} + {%- endcapture -%} + + {% if page.image %} - {% assign img = page.image.path | default: page.image %} + {% assign src = page.image.path | default: page.image %} - {% unless img contains '://' %} - {% assign img_path = page.img_path | append: '/' | append: img | replace: '//', '/' %} - {% capture target %}"{{ img | absolute_url }}"{% endcapture %} + {% unless src contains '://' %} + {%- capture img_url -%} + {% include img-url.html src=src img_path=page.img_path %} + {%- endcapture -%} - {% if site.img_cdn contains '//' %} - - {% capture replacement %}"{{ site.img_cdn }}{{ img_path }}"{% endcapture %} - {% else %} - - {%- capture replacement -%} - "{{ site.img_cdn | append: '/' | append: img_path | replace: '//', '/' | absolute_url }}" - {%- endcapture -%} - {% endif %} + {%- capture old_url -%}{{ src | absolute_url }}{%- endcapture -%} + {%- capture new_url -%}{{ img_url }}{%- endcapture -%} - {% assign seo_tags = seo_tags | replace: target, replacement %} + {% assign seo_tags = seo_tags | replace: old, new %} {% endunless %} + + {% elsif site.social_preview_image %} + {%- capture img_url -%} + {% include img-url.html src=site.social_preview_image %} + {%- endcapture -%} + + {%- capture og_image -%} + + {%- endcapture -%} + + {% assign old_meta_clip = ' - {% if site.img_cdn %} - {% if site.img_cdn contains '//' %} - {% assign _path_prefix = site.img_cdn %} - {% else %} - {% assign _path_prefix = site.img_cdn | relative_url %} - {% endif %} - {% else %} - {% assign _path_prefix = site.baseurl %} - {% endif %} - - - {% if page.img_path %} - {% assign _path = page.img_path | append: '/' | replace: '//', '/' %} - {% assign _path_prefix = _path_prefix | append: _path %} - {% endif %} - {% for _img_snippet in _img_snippets %} {% if forloop.first %} {% assign _img_content = _img_snippet %} @@ -113,6 +96,12 @@ {% assign _final_src = null %} {% assign _lazyload = true %} + {%- capture _img_url -%} + {% include img-url.html src=_src img_path=page.img_path %} + {%- endcapture -%} + + {% assign _path_prefix = _img_url | remove: _src %} + {% unless _src contains '//' %} {% assign _final_src = _path_prefix | append: _src %} {% assign _src_alt = 'src="' | append: _path_prefix %} diff --git a/_includes/sidebar.html b/_includes/sidebar.html index 99d6dcc..b8f92e3 100644 --- a/_includes/sidebar.html +++ b/_includes/sidebar.html @@ -3,18 +3,12 @@