Skip to content

Commit

Permalink
Webp only
Browse files Browse the repository at this point in the history
  • Loading branch information
efiand committed Sep 17, 2023
1 parent 693c96a commit 96d881c
Show file tree
Hide file tree
Showing 60 changed files with 18 additions and 76 deletions.
11 changes: 0 additions & 11 deletions gulp/createWebp.js

This file was deleted.

7 changes: 6 additions & 1 deletion gulp/saveImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import clean from 'gulp-clean';
import gulp from 'gulp';
import processImages from 'gulp-libsquoosh';

const saveImages = () => gulp.src(Path.Images.RASTERS).pipe(processImages()).pipe(clean()).pipe(gulp.dest(Path.Images.PUBLIC));
const saveImages = () =>
gulp
.src(Path.Images.RASTERS)
.pipe(clean())
.pipe(processImages({ webp: { quality: 75 } }))
.pipe(gulp.dest(Path.Images.PUBLIC));

export default saveImages;
7 changes: 2 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import buildSprite from './gulp/buildSprite.js';
import buildStyles from './gulp/buildStyles.js';
import cleanDist from './gulp/cleanDist.js';
import copyStatic from './gulp/copyStatic.js';
import createWebp from './gulp/createWebp.js';
import gulp from 'gulp';
import lintEditorconfig from './gulp/lintEditorconfig.js';
import lintScripts from './gulp/lintScripts.js';
Expand All @@ -18,11 +17,9 @@ const { parallel, series } = gulp;

export const lint = parallel(lintEditorconfig, lintScripts, lintStyles, series(buildSvelteSsr, processLayouts));

const compile = series(
export const build = series(
cleanDist,
parallel(lint, saveIcons, saveImages, saveSvg),
parallel(buildScripts, buildSprite, buildStyles, copyStatic)
);

export const build = series(compile, createWebp);
export default series(compile, startWatch);
export default series(build, startWatch);
Binary file removed public/images/bg-reviews.jpg
Binary file not shown.
Binary file added public/images/bg-reviews.webp
Binary file not shown.
Binary file removed public/images/bg-reviews@2x.jpg
Binary file not shown.
Binary file added public/images/bg-reviews@2x.webp
Binary file not shown.
Binary file removed public/images/good-1-desktop.jpg
Binary file not shown.
Binary file added public/images/good-1-desktop.webp
Binary file not shown.
Binary file removed public/images/good-1-desktop@2x.jpg
Binary file not shown.
Binary file added public/images/good-1-desktop@2x.webp
Binary file not shown.
Binary file removed public/images/good-1-tablet.jpg
Binary file not shown.
Binary file added public/images/good-1-tablet.webp
Binary file not shown.
Binary file removed public/images/good-1-tablet@2x.jpg
Binary file not shown.
Binary file added public/images/good-1-tablet@2x.webp
Binary file not shown.
Binary file removed public/images/good-1.jpg
Binary file not shown.
Binary file added public/images/good-1.webp
Binary file not shown.
Binary file removed public/images/good-1@2x.jpg
Binary file not shown.
Binary file added public/images/good-1@2x.webp
Binary file not shown.
Binary file removed public/images/good-2-desktop.jpg
Binary file not shown.
Binary file added public/images/good-2-desktop.webp
Binary file not shown.
Binary file removed public/images/good-2-desktop@2x.jpg
Binary file not shown.
Binary file added public/images/good-2-desktop@2x.webp
Binary file not shown.
Binary file removed public/images/good-2-tablet.jpg
Binary file not shown.
Binary file added public/images/good-2-tablet.webp
Binary file not shown.
Binary file removed public/images/good-2-tablet@2x.jpg
Binary file not shown.
Binary file added public/images/good-2-tablet@2x.webp
Binary file not shown.
Binary file removed public/images/good-2.jpg
Binary file not shown.
Binary file added public/images/good-2.webp
Binary file not shown.
Binary file removed public/images/good-2@2x.jpg
Binary file not shown.
Binary file added public/images/good-2@2x.webp
Binary file not shown.
Binary file removed public/images/good-3-desktop.jpg
Binary file not shown.
Binary file added public/images/good-3-desktop.webp
Binary file not shown.
Binary file removed public/images/good-3-desktop@2x.jpg
Binary file not shown.
Binary file added public/images/good-3-desktop@2x.webp
Binary file not shown.
Binary file removed public/images/good-3-tablet.jpg
Binary file not shown.
Binary file added public/images/good-3-tablet.webp
Binary file not shown.
Binary file removed public/images/good-3-tablet@2x.jpg
Binary file not shown.
Binary file added public/images/good-3-tablet@2x.webp
Binary file not shown.
Binary file removed public/images/good-3.jpg
Binary file not shown.
Binary file added public/images/good-3.webp
Binary file not shown.
Binary file removed public/images/good-3@2x.jpg
Binary file not shown.
Binary file added public/images/good-3@2x.webp
Binary file not shown.
Binary file removed public/images/good-4.jpg
Binary file not shown.
Binary file added public/images/good-4.webp
Binary file not shown.
Binary file removed public/images/good-4@2x.jpg
Binary file not shown.
Binary file added public/images/good-4@2x.webp
Binary file not shown.
Binary file removed public/images/main-header.jpg
Binary file not shown.
Binary file added public/images/main-header.webp
Binary file not shown.
Binary file removed public/images/main-header@2x.jpg
Binary file not shown.
Binary file added public/images/main-header@2x.webp
Binary file not shown.
Binary file removed public/images/map.jpg
Binary file not shown.
Binary file added public/images/map.webp
Binary file not shown.
Binary file removed public/images/poster.jpg
Diff not rendered.
Binary file added public/images/poster.webp
Binary file not shown.
Binary file removed public/images/poster@2x.jpg
Diff not rendered.
Binary file added public/images/poster@2x.webp
Binary file not shown.
22 changes: 1 addition & 21 deletions src/components/Picture/Picture.twig
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
<picture class="Picture {{ bemMix }}">
{% set ext = ext ?? 'jpg' %}

{% if not devMode and ext != 'svg' %}
{% if adaptive %}
<source
type="image/webp"
media="(min-width: {{ Breakpoint.DESKTOP }}px)"
srcset="{{ rootPath }}images/{{ filename }}-desktop.webp 1x, {{ rootPath }}images/{{ filename }}-desktop@2x.webp 2x"
/>
<source
type="image/webp"
media="(min-width: {{ Breakpoint.TABLET }}px)"
srcset="{{ rootPath }}images/{{ filename }}-tablet.webp 1x, {{ rootPath }}images/{{ filename }}-tablet@2x.webp 2x"
/>
{% endif %}

<source
type="image/webp"
srcset="{{ rootPath }}images/{{ filename }}.webp 1x, {{ rootPath }}images/{{ filename }}@2x.webp 2x"
/>
{% endif %}
{% set ext = ext ?? 'webp' %}

{% if adaptive %}
{% if ext != 'svg' %}
Expand Down
9 changes: 1 addition & 8 deletions src/layouts/utils.twig
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{% macro setBg(set, immediately = false) %}
{% set ext = set.ext ?? 'jpg' -%}
{% set ext = set.ext ?? 'webp' -%}

{{ not immediately ? 'data-lazy-'}}style="{{- '--bgMobile: url(\'../images/' ~ set.filename ~ '.' ~ ext ~ '\');' -}}

{% if ext != 'svg' %}
{{- '--bgMobile2x: url(\'../images/' ~ set.filename ~ '@2x.' ~ ext ~ '\');' -}}
{{- '--bgWebpMobile: url(\'../images/' ~ set.filename ~ '.webp\');' -}}
{{- '--bgWebpMobile2x: url(\'../images/' ~ set.filename ~ '@2x.webp\');' -}}
{% endif -%}

{%- if set.adaptive %}
Expand All @@ -15,12 +13,7 @@

{% if ext != 'svg' %}
{{- '--bgTablet2x: url(\'../images/' ~ set.filename ~ '-tablet@2x.' ~ ext ~ '\');' -}}
{{- '--bgWebpTablet: url(\'../images/' ~ set.filename ~ '-tablet.webp\');' -}}
{{- '--bgWebpTablet2x: url(\'../images/' ~ set.filename ~ '-tablet@2x.webp\');' -}}

{{- '--bgDesktop2x: url(\'../images/' ~ set.filename ~ '-desktop@2x.' ~ ext ~ '\');' -}}
{{- '--bgWebpDesktop: url(\'../images/' ~ set.filename ~ '-desktop.webp\');' -}}
{{- '--bgWebpDesktop2x: url(\'../images/' ~ set.filename ~ '-desktop@2x.webp\');' -}}
{% endif %}
{% endif -%}

Expand Down
38 changes: 8 additions & 30 deletions src/styles/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,51 +146,29 @@
}
}

@mixin webpBackground($webp, $fallback) {
@if devMode() {
background-image: $fallback;
} @else {
@supports (background-image: $webp) {
background-image: $webp;
}
@mixin retinalBackground($bg) {
background-image: var(--bg#{$bg});

@supports not (background-image: $webp) {
background-image: $fallback;
}
@include retina {
background-image: var(--bg#{$bg}2x);
}
}

@mixin customBackground($adaptive: true) {
@if $adaptive {
@include vpMobile {
@include webpBackground(var(--bgWebpMobile), var(--bgMobile));

@include retina {
@include webpBackground(var(--bgWebpMobile2x), var(--bgMobile2x));
}
@include retinalBackground("Mobile");
}

@include vpTablet {
@include webpBackground(var(--bgWebpTablet), var(--bgTablet));

@include retina {
@include webpBackground(var(--bgWebpTablet2x), var(--bgTablet2x));
}
@include retinalBackground("Tablet");
}

@include vpDesktop {
@include webpBackground(var(--bgWebpDesktop), var(--bgDesktop));

@include retina {
@include webpBackground(var(--bgWebpDesktop2x), var(--bgDesktop2x));
}
@include retinalBackground("Desktop");
}
} @else {
@include webpBackground(var(--bgWebpMobile), var(--bgMobile));

@include retina {
@include webpBackground(var(--bgWebpMobile2x), var(--bgMobile2x));
}
@include retinalBackground("Mobile");
}
}

Expand Down

0 comments on commit 96d881c

Please sign in to comment.