Skip to content

Commit

Permalink
merge dev into master
Browse files Browse the repository at this point in the history
  • Loading branch information
willpatera committed Jun 15, 2017
2 parents 81f320f + e023343 commit b679829
Show file tree
Hide file tree
Showing 16 changed files with 992 additions and 56 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ before_install:
- ./deploy_before_install.sh
# install: not required :)
script:
- gulp webp:make
- echo 'Building Site'
- gulp build --production
- gulp image_min
Expand Down
38 changes: 36 additions & 2 deletions assets/stylus/components/feature.styl
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@
background-size cover
backface-visibility: hidden


.img-placeholder
// nothing here yet

.img-large
.img-small
.img-large--webp
opacity 0

.img-loaded
Expand All @@ -227,6 +227,40 @@
filter blur(50px)
transform scale(1)

.img-small--webp
opacity 1
filter blur(20px)
transform scale(1)

.img-small--webp
&.lazyloaded
opacity 0
transition opacity .1s linear

.img-large--webp
&.lazyloaded
opacity 1
transition opacity .1s linear

.lazy-img
margin auto
overflow hidden

.ratio-box
position relative
height 0
display block

.ratio-box img
.ratio-box iframe
.ratio-box video
position absolute
top 0
left 0
width 100%
height 100%
display block

.Background-img--full-wh-grid
background-position center center
background-repeat no-repeat
Expand Down
5 changes: 4 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"require": {
"moment": "moment",
"_": "underscore",
"typogr": "typogr"
"typogr": "typogr",
"imageSize": "image-size",
"fs": "fs",
"path": "path"
},
"jade": {
"pretty": true
Expand Down
5 changes: 4 additions & 1 deletion config_production.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"require": {
"moment": "moment",
"_": "underscore",
"typogr": "typogr"
"typogr": "typogr",
"imageSize": "image-size",
"fs": "fs",
"path": "path"
},
"jade": {
"pretty": true
Expand Down
5 changes: 4 additions & 1 deletion config_staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"require": {
"moment": "moment",
"_": "underscore",
"typogr": "typogr"
"typogr": "typogr",
"imageSize": "image-size",
"fs": "fs",
"path": "path"
},
"jade": {
"pretty": true
Expand Down
2 changes: 2 additions & 0 deletions contents/js/vendor/lazysizes.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contents/media
58 changes: 57 additions & 1 deletion gulpfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ uncss = require "gulp-uncss"
clean = require "gulp-clean"
rev = require 'gulp-rev'
rev_replace = require 'gulp-rev-replace'
webp = require 'gulp-webp'
size = require 'gulp-size'
rename = require 'gulp-rename'
imgResize = require 'gulp-image-resize'

# =================================================================
# high level tasks
Expand All @@ -43,7 +47,7 @@ gulp.task "build", (cb)->

gulp.task "preview", (cb)->
return runSequence ['build:clean', 'js:clean'],
['css:build','js:build'],
['css:build','js:build', 'webp:make'],
'build_wintersmith',
'css:clean',
cb
Expand Down Expand Up @@ -191,6 +195,55 @@ gulp.task 'image_min', ->
.pipe(image_min(options))
.pipe(gulp.dest('./'))

# =================================================================
# lazyload & webp tasks
# =================================================================

gulp.task "img:make", (cb)->
return runSequence 'webp:make',
'img:make:previews'
cb

gulp.task "img:clean", (cb)->
return runSequence 'jpeg:format',
'jpeg:clean'
cb

gulp.task "jpeg:clean", ->
return gulp.src('contents/media/images/**/*.{jpeg}',{read:false})
.pipe(clean())

gulp.task "jpeg:format", ->
return gulp.src('contents/media/images/**/*.{jpeg}',{base: './'})
.pipe plumber()
.pipe imgResize({format: 'jpg'})
.pipe(gulp.dest('./'))

gulp.task 'img:make:previews', ->
options = {
resize: [20,20],
quality: 85,
progressive: true,
compressionLevel: 6,
sequentialRead: true,
trellisQuantisation: false
}

return gulp.src('./build/media/images/**/*.{jpg,png}',{base: './'})
.pipe(plumber())
.pipe(image_min(options))
.pipe rename
suffix: '_preview'
.pipe(gulp.dest('./'))

gulp.task 'webp:make', ->
return gulp.src('./contents/media/images/**/*.{jpg,png}',{base: './'})
.pipe plumber()
.pipe size()
.pipe webp
quality: 80
.pipe size()
.pipe gulp.dest('./')

# =================================================================
# site compile tasks
Expand Down Expand Up @@ -330,6 +383,9 @@ gulp.task "css:clean", ->
new RegExp('^.parsley-.*')
new RegExp('^.datalist.*')
new RegExp('^li.active.*')
new RegExp('^.lazyloaded.*')
new RegExp('^.img-large--webp.*')
new RegExp('^.img-small--webp.*')
]
))
.pipe(gulp.dest('build/css'))
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"gulp-coffee": "^2.3.3",
"gulp-concat": "^2.6.1",
"gulp-favicons": "^2.2.7",
"gulp-image-resize": "^0.12.0",
"gulp-plumber": "^1.1.0",
"gulp-rename": "^1.2.2",
"gulp-rev": "^7.1.2",
"gulp-rev-replace": "^0.4.3",
"gulp-sharp-minimal": "git+https://github.com/pupil-labs/gulp-sharp-minimal.git",
Expand All @@ -36,6 +38,8 @@
"gulp-uglify": "^2.0.0",
"gulp-uncss": "^1.0.6",
"gulp-util": "^3.0.7",
"gulp-webp": "^2.3.0",
"image-size": "^0.5.4",
"minimist": "^1.2.0",
"run-sequence": "^1.2.2",
"run-wintersmith": "^0.0.3"
Expand Down
10 changes: 7 additions & 3 deletions templates/blog.jade
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ block main

div.Site-content-container

include includes/webp-img

div.Grid.Grid--1of2.Grid--gutters-lg
each article, i in articles.slice(1)

- var img_src = (article.metadata.featured_img_thumb ? article.metadata.featured_img_thumb : "https://placehold.it/800x600")
- var img_thumb = article.metadata.featured_img_thumb
- var img_src = (img_thumb ? img_thumb : "https://placehold.it/800x600")


div.Grid-cell

Expand All @@ -53,9 +57,9 @@ block main
div.Caption-tag= article.metadata.tag.caption

else

a(href=article.url)
div.Feature-image--blog-archive--wrapper.Grid--center.Grid--justifyCenter.Grid-cell--fillHeight
div(src=img_src style="background-image: url('"+img_src+"');").Background-img--blog-archive.Background-img-contain
+webp-img(img_thumb, article.title, article.title, "height:30vh;", "object-fit:contain;height:30vh;padding-bottom:3em;")

a(href=article.url)
h2.Blog-article-title= article.title
Expand Down
4 changes: 2 additions & 2 deletions templates/home.jade
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ block main
h1.Background-img-caption Open source eye tracking.
//- h2.Background-img--caption-h2
include includes/webp-img
//- pupil intro row
div(id="content-top" class="Site-content-container")
div.Feature-container-column
Expand All @@ -39,8 +40,7 @@ block main
p All hardware is designed, developed, and assembled in our Berlin office and ships worldwide. Check out products on our #[a(href="/store" title="Pupil Labs store") store].
div.Grid-cell
figure.Feature-figure.u-padBottom--1
img(class="Feature-image" src="media/images/home/platform/eye_debug_01_opaque.png" title="Binocular 3D gaze mapper" alt="Binocular 3D gaze mapper")

+webp-img("/media/images/home/platform/eye_debug_01_opaque.png", "Binocular 3D gaze mapper", "Binocular 3D gaze mapper")

//- oss motivation row
div.Site-gray-bkg
Expand Down
3 changes: 3 additions & 0 deletions templates/includes/js.jade
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//- js lazysizes
script(src=contents.js.vendor['lazysizes.min.js'].url)

//- google jquery and jquery fallback
script(src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js")
script.
Expand Down
69 changes: 69 additions & 0 deletions templates/includes/webp-img.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
mixin webp-img(src, title, alt, picture_style, img_style)

//- remove img src path suffix
- var path_nosuffix = src.replace(/[.][a-z]+/,"");
//- get absolute path from the src path and remove suffix
- var absolute_path = (path.resolve("./contents"+src.match(/\/media.+/, "")));
- var absolute_nosuffix = absolute_path.replace(/[.][a-z]+/,"");

//- sources is an array of [str : image_type/suffix, bool : file exists]
//- The order of this array is important as it specifies the order we want sources within the picture element.
- var sources = [["webp", false],["jpg", false],["png", false]];

//- Update sources array.
//- For each source, check if the file type exists. bool true if exists
- for (i in sources) {
- var suffix = sources[i][0];
- sources[i][1] = fs.existsSync(absolute_nosuffix+"."+suffix);
- };

//- Add all sources with valid file path (all sources that exist).
- var filtered_sources = sources.filter(function(e,i,a){
- return e[1] === true;
- });

//- filtered_sources = [] if no valid source
- var no_sources, preferred_src_suffix;
//- overwrite filtered_sources with new array with jpg only
- if (filtered_sources.length > 0) {
- no_sources = filtered_sources.every(function(e,i,a){
- return !e[1];
- });
- preferred_src_suffix = filtered_sources[0][0];
- } else {
- console.log("no valid source ! "+src);
- no_sources = true;
- preferred_src_suffix = 'jpg';
- }

//- This is a workaround and not a long term solution.
//- This assumes that if there is no function argument specified for picture_style,
//- then we assume that it is not a blog post then calculate img ratio from image dimensions instead
- if (!picture_style && !no_sources){
- var img_size = imageSize("./contents" + src );
- var width = img_size.width;
- var height = img_size.height;
- }

- picture_style = !picture_style ? "" : picture_style;
- img_style = !img_style ? "" : img_style;
- var ratio = picture_style.length > 0 ? picture_style : "padding-bottom: " + (height/width)*100 + "%;" ;
- var img_style = img_style.length > 0 ? img_style : "";
- var placeholder_img = no_sources

//- If there is no source img found then a placeholder img link is supplied as the path instead
- if (no_sources){
- filtered_sources = [['jpg', true]];
- path_nosuffix = 'http://via.placeholder.com/400';
- ratio = "padding-bottom: 100%;";
- img_style = "width:initial;height:initial";
- }

picture(style=ratio).ratio-box.lazy-img
for i in filtered_sources
- suffix = i[0]
source(srcset="#{path_nosuffix}.#{suffix}" type="image/#{suffix}")

//- add src path and use suffix for images that exists
img(src="#{path_nosuffix}.#{preferred_src_suffix}" style=img_style).img-small--webp.lazyload
img(data-src="#{path_nosuffix}.#{preferred_src_suffix}" style=img_style title="#{title}" alt="#{alt}").img-large--webp.lazyload
11 changes: 6 additions & 5 deletions templates/pupil.jade
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ block main
div.Feature.u-padTop--2
h4 Navigate to the #[a(href='/store#pupil' title='Pupil Store - pupil configurator') store] to check all configurations, technical specs, and download sample videos.


include includes/webp-img

//- open source
div.Site-gray-bkg
Expand All @@ -180,8 +182,7 @@ block main
div.Grid-cell
div.Feature
figure.Feature-figure
img(class="Feature-image" src="../media/images/pupil_page/web/pupil_source_code.png" title="Pupil Plugin screenshot" alt="Pupil Plugin screenshot")

+webp-img("/media/images/pupil_page/web/pupil_source_code.png", "Pupil Plugin screenshot" , "Pupil Plugin screenshot")

//- design
div.Site-content-container
Expand All @@ -197,8 +198,7 @@ block main
div.Grid-cell
div.Feature
figure.Feature-figure
img(class="Feature-image" src="../media/images/pupil_page/web/frame_flex.jpg" title="Pupil Headset" alt="Pupil Headset")

+webp-img("/media/images/pupil_page/web/frame_flex.jpg", "Pupil Headset" , "Pupil Headset")

//- Modular & Hackable
div.Site-gray-bkg
Expand All @@ -210,7 +210,8 @@ block main
div.Feature
figure.Feature-figure
figure.Feature-figure
img(class="Feature-image" src="../media/images/pupil_page/web/dev_explo_transp.png" title="DIY Pupil Headset" alt="DIY Pupil Headset")
+webp-img("/media/images/pupil_page/web/dev_explo_transp.png", "DIY Pupil Headset" , "DIY Pupil Headset")

div.Grid-cell
div.Feature
h1 Modular & Hackable
Expand Down
Loading

0 comments on commit b679829

Please sign in to comment.