-
-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] use appropriate-images for examples to increase page speed (#7…
…900) * use appropriate-images for examples * move @mapbox/appropriate-images to optionalDependencies * class -> className * rm docs/img/dist * ignore docs/img/dist * create `build-images` script to run appropriate-images on `build-docs` and `start-docs`; move appropriate-images as devDep * add note to documentation to suggust using `nvm use 8` if contributor receives error * remove test to check for generated image in dist/ * automate image.config.js and update documentation * add eslint-disable-line as image.config.json is generated on build
- Loading branch information
1 parent
1f12aa7
commit 6d04166
Showing
108 changed files
with
1,843 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const path = require('path'); // eslint-disable-line import/no-commonjs | ||
const appropriateImages = require('@mapbox/appropriate-images'); // eslint-disable-line import/no-commonjs | ||
const imageConfig = require('../img/dist/image.config.json'); // eslint-disable-line import/no-commonjs | ||
|
||
appropriateImages.createCli(imageConfig, { | ||
inputDirectory: path.join(__dirname, '../img/src'), | ||
outputDirectory: path.join(__dirname, '../img/dist') | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env node | ||
// builds image.config.json | ||
// this configuration file is required to generate the appropriate images sizes with docs/bin/appropriate-images.js | ||
// it is also required in react component that loads the image in components/appropriate-image.js | ||
const imagePath = './docs/img/src/'; | ||
|
||
const imageConfig = require('fs').readdirSync(imagePath).reduce((obj, image) => { | ||
const ext = require('path').extname(`${imagePath}${image}`); | ||
// only process png | ||
if (ext === '.png') { | ||
const key = image.replace(ext, ''); | ||
// set sizes for all images | ||
const sizes = [{ width: 800 }, { width: 500 }]; | ||
// set additional sizes for specific images | ||
if (key === 'simple-map') sizes.push({ width: 1200 }); | ||
obj[key] = { | ||
basename: image, | ||
sizes | ||
}; | ||
} | ||
return obj; | ||
}, {}); | ||
|
||
require('fs').writeFileSync('./docs/img/dist/image.config.json', JSON.stringify(imageConfig)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { scopeAppropriateImage } from '@mapbox/appropriate-images-react'; | ||
import imageConfig from '../img/dist/image.config.json'; // eslint-disable-line import/no-unresolved | ||
// image.config.json is generated on build | ||
|
||
// See https://github.com/mapbox/appropriate-images-react#appropriateimage | ||
// The required prop is `imageId`, which must correspond to a key in the | ||
// imageConfig. | ||
const AppropriateImage = scopeAppropriateImage(imageConfig, { | ||
transformUrl: url => require(`../img/dist/${url}`) | ||
}); | ||
|
||
export default AppropriateImage; |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.