1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-18 05:41:31 +00:00

Add image CDN support & improve image lazy loading

This commit is contained in:
Cotes Chung
2021-01-09 22:30:31 +08:00
parent 594eaf5100
commit 6e6633c2fc
5 changed files with 52 additions and 22 deletions

View File

@@ -47,21 +47,13 @@ layout: default
</div> <!-- .post-meta -->
<div class="post-content">
{%- capture img_placehodler -%}
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
{%- endcapture -%}
{% if page.image %}
<img src="{{ img_placehodler }}" data-src="{{ page.image }}" class="preview-img">
<img src="{{ page.image }}" class="preview-img" alt="Preview Image">
{% endif %}
<!-- Using lozad. See: <https://github.com/ApoorvSaxena/lozad.js#usage> -->
{% if content contains '<img src=' %}
{% assign replacement = '<img src="' | append: img_placehodler | append: '" data-src=' %}
{{ content | replace: '<img src=', replacement }}
{% else %}
{{ content }}
{% endif %}
{{ content }}
</div>
<div class="post-tail-wrapper text-muted">
@@ -140,5 +132,3 @@ layout: default
</div> <!-- .col-* -->
</div> <!-- .row -->
{% include lozad.html %}