File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<!-- image lazy load: https://github.com/ApoorvSaxena/lozad.js -->
22< script type ="text/javascript " src ="https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js "> </ script >
3+
34< script type ="text/javascript ">
4- const el = document . querySelectorAll ( '#post-wrapper img' ) ;
5- const observer = lozad ( el ) ;
5+ const imgs = document . querySelectorAll ( '#post-wrapper img' ) ;
6+ const observer = lozad ( imgs ) ;
67 observer . observe ( ) ;
78</ script >
Original file line number Diff line number Diff line change @@ -64,13 +64,19 @@ <h1 data-toc-skip>{{ page.title }}</h1>
6464 </ div > <!-- .post-meta -->
6565
6666 < div class ="post-content ">
67-
6867 {% if page.image %}
6968 < img src ="{{ page.image }} ">
7069 {% endif %}
71-
72- {{ content }}
73-
70+ <!-- Add lozad class into image tags. see: <https://github.com/ApoorvSaxena/lozad.js#usage> -->
71+ {% if content contains '< img src =' %}
72+ {% capture loading %}
73+ {{ "/assets/img/commons/loading.png" | relative_url }}
74+ {% endcapture %}
75+ {% assign replacement = '< img src =' | append: loading | append: ' data-src =' %}
76+ {{ content | replace: '< img src =', replacement }}
77+ {% else %}
78+ {{ content }}
79+ {% endif %}
7480 </div>
7581
7682 <div class="post-tail-wrapper text-muted">
You can’t perform that action at this time.
0 commit comments