Skip to content

Commit

Permalink
fix: scripts for optimizing images
Browse files Browse the repository at this point in the history
  • Loading branch information
plibither8 committed Sep 10, 2020
1 parent 8fa5693 commit 4553fb5
Show file tree
Hide file tree
Showing 8 changed files with 2,580 additions and 209 deletions.
2,669 changes: 2,515 additions & 154 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
"build": "sapper build --legacy",
"export": "sapper export --legacy",
"start": "node __sapper__/build",
"clean-after": "rimraf __sapper__/export/images/**/*.webp",
"optimize-images": "node scripts/optimize-images",
"prod": "run-s export clean-after optimize-images",
"lint": "eslint . --ext .js,.svelte",
"lint:fix": "eslint . --ext .js,.svelte --fix"
},
"dependencies": {
"compression": "^1.7.4",
"email-validator": "^2.0.4",
"imagemin": "^7.0.1",
"imagemin-webp": "^6.0.0",
"polka": "next",
"sirv": "^1.0.6"
},
Expand All @@ -36,11 +41,13 @@
"eslint-plugin-svelte3": "^2.7.3",
"node-sass": "^4.14.1",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"rollup": "^2.26.11",
"rollup-plugin-svelte": "^6.0.1",
"rollup-plugin-terser": "^7.0.2",
"sapper": "^0.28.6",
"svelte": "^3.24.1",
"svelte-image": "^0.2.7",
"svelte-preprocess": "^4.2.1"
}
}
27 changes: 27 additions & 0 deletions scripts/optimize-images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const path = require('path')
const imagemin = require('imagemin')
const webp = require('imagemin-webp')

const webpOptions = {
quality: 75,
lossless: false,
force: true
}

const sources = [
{ // Sponsors
input: path.resolve('./static/images/sponsors/') + '/*',
output: path.resolve('./__sapper__/export/images/sponsors/')
},
{ // People
input: path.resolve('./static/images/people/') + '/*',
output: path.resolve('./__sapper__/export/images/people/')
}
]

for (const source of sources) {
imagemin([source.input], {
destination: source.output,
plugins: [webp(webpOptions)]
})
}
13 changes: 13 additions & 0 deletions src/components/image.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
export let alt
export let src
const webpSrc = [src.split('.').slice(0, -1), 'webp'].join('.')
</script>

<picture>
{#if process.env.NODE_ENV !== 'development'}
<source srcset='{webpSrc}' type='image/webp'>
{/if}
<source srcset='{src}' type='image/jpeg'>
<img {src} {alt}>
</picture>
6 changes: 4 additions & 2 deletions src/components/sections/contact.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script>
import contacts from '../../../data/contacts.yml'
import Section from '../section.svelte'
import Image from '../image.svelte'
</script>

<Section id={'contact'} heading={'Contact'} >
Expand All @@ -10,7 +12,7 @@
<div class="gallery">
{#each contacts as contact}
<div class="contact">
<img src={contact.image} alt="{contact.name} photo">
<Image src={contact.image} alt="{contact.name} photo" />
<h3>{contact.name}</h3>
<h4>{contact.post}</h4>
<p><span>Phone:</span> <a href="tel:{contact.phone}">{contact.phone}</a></p>
Expand Down Expand Up @@ -53,7 +55,7 @@
flex: 1;
white-space: nowrap;
img {
:global(img) {
height: 150px;
border-radius: 10px;
margin-bottom: 30px;
Expand Down
26 changes: 14 additions & 12 deletions src/components/sections/sponsors.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<script>
import sponsors from '../../../data/sponsors.yml'
import Section from '../section.svelte'
import LinkIcon from '../icons/link.svelte'
import Image from '../image.svelte'
</script>

<Section id={'sponsors'} heading={'Sponsors'} >
<div class="gallery">
{#each sponsors as sponsor}
<a href='{sponsor.link}' target='_blank' rel='noopener'>
<div class="image-wrapper">
<img src={sponsor.image} alt="{sponsor.name} logo"/>
<Image src={sponsor.image} alt="{sponsor.name} logo" />
</div>
<span>
{sponsor.name}
Expand Down Expand Up @@ -45,7 +47,7 @@
&:active {
opacity: 1;
img {
:global(img) {
filter: saturate(100%);
transform: scale(1.1);
}
Expand All @@ -62,18 +64,18 @@
display: flex;
align-items: center;
margin-bottom: 20px;
}
img {
max-height: 75px;
max-width: 250px;
align-self: center;
border-radius: 10px;
transition: 0.1s all ease-in-out;
filter: saturate(0%);
:global(img) {
max-height: 75px;
max-width: 250px;
align-self: center;
border-radius: 10px;
transition: 0.1s all ease-in-out;
filter: saturate(0%);
@media only screen and (max-width: 800px) {
filter: saturate(75%);
@media only screen and (max-width: 800px) {
filter: saturate(75%);
}
}
}
}
Expand Down
40 changes: 0 additions & 40 deletions src/routes/_error.svelte

This file was deleted.

1 change: 0 additions & 1 deletion static/robots.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *

0 comments on commit 4553fb5

Please sign in to comment.