mirror of
https://github.com/cotes2020/jekyll-theme-chirpy.git
synced 2025-12-18 05:41:31 +00:00
Simplified the lazy loading of post images.
This commit is contained in:
@@ -64,19 +64,13 @@ layout: default
|
||||
</div> <!-- .post-meta -->
|
||||
|
||||
<div class="post-content">
|
||||
|
||||
{% if page.image %}
|
||||
<img src="{{ page.image }}">
|
||||
{% endif %}
|
||||
<!-- Add lozad class into image tags. see: <https://github.com/ApoorvSaxena/lozad.js#usage> -->
|
||||
{% if content contains '<img src=' %}
|
||||
{% capture loading %}
|
||||
{{ "/assets/img/commons/loading.png" | relative_url }}
|
||||
{% endcapture %}
|
||||
{% assign replacement = '<img class="lozad" src=' | append: loading | append: ' data-src=' %}
|
||||
{{ content | replace: '<img src=', replacement }}
|
||||
{% else %}
|
||||
{{ content }}
|
||||
<img src="{{ page.image }}">
|
||||
{% endif %}
|
||||
|
||||
{{ content }}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="post-tail-wrapper text-muted">
|
||||
|
||||
Reference in New Issue
Block a user