Skip to content

Commit

Permalink
add new webp mixin for blog
Browse files Browse the repository at this point in the history
  • Loading branch information
nathakits committed May 30, 2017
1 parent daa1588 commit 4530231
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions templates/includes/blog_webp.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mixin picture(path, title, alt)
- var img_path = path.replace(/([.]{2}\/){4}/, "");
- var updated_path = "../../contents/"+img_path

- var img_size = imageSize( path );
- var path_nosuffix = path.replace(/[.][a-z]{3}/, "")
- var width = img_size.width;
- var height = img_size.height;
- var ratio = "padding-bottom: " + (height/width)*100 + "%;";

picture(style=ratio).ratio-box.lazy-img
source(srcset="#{path_nosuffix}.webp" type="image/webp")
source(srcset="#{path_nosuffix}.png" type="image/png")
source(srcset="#{path_nosuffix}.jpg" type="image/jpeg")
img(src="#{path_nosuffix}.webp").img-small
img(data-src="#{path_nosuffix}.webp" title="#{title}" alt="#{alt}").img-large-webp.lazyload

0 comments on commit 4530231

Please sign in to comment.