diff --git a/_includes/refactor-content.html b/_includes/refactor-content.html index 69d43b4..b47e0a9 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 %} 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: