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 1/2] 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 %} From ef2aa525d589e2d71ed137e366a7ae537c79f323 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Tue, 14 Dec 2021 23:29:07 +0800 Subject: [PATCH 2/2] Add intro for `img_path` --- _posts/2019-08-08-write-a-new-post.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/_posts/2019-08-08-write-a-new-post.md b/_posts/2019-08-08-write-a-new-post.md index 68f0358..0914298 100644 --- a/_posts/2019-08-08-write-a-new-post.md +++ b/_posts/2019-08-08-write-a-new-post.md @@ -206,6 +206,31 @@ The parsing result will automatically add the CDN prefix `https://cdn.com` befor ``` {: .nolineno} +### Image path + +When a post contains many images, it will be a time-consuming task to repeatedly define the path of the images. To solve this, we can define this path in the YAML block of the post: + +```yml +--- +img_path: /img/path/ +--- +``` +{: .nolineno } + +And then, the image source of Markdown can write the file name directly: + +```md +![The flower](flower.png) +``` +{: .nolineno } + +The output will be: + +```html +The flower +``` +{: .nolineno } + ## Pinned Posts You can pin one or more posts to the top of the home page, and the fixed posts are sorted in reverse order according to their release date. Enable by: