From 1fe0b2958b97e3e630c1dfdf2a834f3fd7411af8 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Tue, 14 Dec 2021 23:28:15 +0800 Subject: [PATCH] Add new variable `img_path` for posts --- _includes/refactor-content.html | 101 +++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 33 deletions(-) diff --git a/_includes/refactor-content.html b/_includes/refactor-content.html index d958cda..f7f6dde 100644 --- a/_includes/refactor-content.html +++ b/_includes/refactor-content.html @@ -38,65 +38,100 @@ %} {% endif %} - -{% if _content contains ' + {% if site.img_cdn %} + {% assign _src_prefix = site.img_cdn %} + {% else %} + {% assign _src_prefix = site.baseurl %} + {% endif %} + + + {% if page.img_path %} + {% assign _path = page.img_path %} + {% assign last_char = _path | slice: -1 %} + + {% unless last_char == '/' %} + {% assign _path = _path | append: '/' %} + {% endunless %} + + {% assign _src_prefix = _src_prefix | append: _path %} + {% endif %} + + {% assign _final_src = _src_prefix | append: _src %} + {% assign _left = _left | replace: _src, _final_src %} + + {% endunless %} + + + + {% assign _left = _left | replace: 'src=', 'data-src=' %} + + {% endif %} + + + + {% if _width and _height %} + {%- capture _svg -%} + src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 {{ _width }} {{ _height }}'%3E%3C/svg%3E" + {%- endcapture -%} + + {% assign _left = _svg | append: ' ' | append: _left %} + {% endif %} + + + {% assign _left = _left | append: ' data-proofer-ignore' %} + + {% assign _img_content = _img_content | append: IMG_TAG | append: _left | append: _right %} {% endfor %}