DRY resize-images options
This commit is contained in:
parent
7865b630f9
commit
65a67da803
2 changed files with 14 additions and 6 deletions
|
|
@ -7,10 +7,13 @@ const sharp = require('sharp')
|
||||||
const glob = util.promisify(globCb)
|
const glob = util.promisify(globCb)
|
||||||
const readFile = util.promisify(fs.readFile)
|
const readFile = util.promisify(fs.readFile)
|
||||||
|
|
||||||
|
const { sizes, resizedDir, outputDir } = require('../src/util/getImageUrl')
|
||||||
|
const dirPrefix = './public'
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
inputDir: './public/images/uploads',
|
sizes,
|
||||||
outputDir: './public/images/uploads/resized',
|
inputDir: `${dirPrefix}${outputDir}`,
|
||||||
sizes: [10, 300, 600, 1200, 1800],
|
outputDir: `${dirPrefix}${resizedDir}`,
|
||||||
imageFormats: ['jpg', 'jpeg', 'png', 'gif', 'webp']
|
imageFormats: ['jpg', 'jpeg', 'png', 'gif', 'webp']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,9 @@ const parseFilename = filename => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const getImageSrcset = path => {
|
const getImageSrcset = path => {
|
||||||
if (!path || path.match(/^http/) || path.match(/svg$/) || window.CMS) { return null }
|
if (!path || path.match(/^http/) || path.match(/svg$/) || window.CMS) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
const { filename, extname } = parseFilename(path)
|
const { filename, extname } = parseFilename(path)
|
||||||
const pathname = encodeURI(filename.replace(outputDir, resizedDir))
|
const pathname = encodeURI(filename.replace(outputDir, resizedDir))
|
||||||
|
|
||||||
|
|
@ -22,7 +24,9 @@ const getImageSrcset = path => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const getImageSrc = (path, sizeRequested) => {
|
const getImageSrc = (path, sizeRequested) => {
|
||||||
if (!path || path.match(/^http/) || path.match(/svg$/) || window.CMS) { return path }
|
if (!path || path.match(/^http/) || path.match(/svg$/) || window.CMS) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
sizeRequested = parseInt(sizeRequested, 10)
|
sizeRequested = parseInt(sizeRequested, 10)
|
||||||
let size
|
let size
|
||||||
if (sizeRequested) {
|
if (sizeRequested) {
|
||||||
|
|
@ -43,5 +47,6 @@ module.exports = {
|
||||||
getImageSrcset,
|
getImageSrcset,
|
||||||
getImageSrc,
|
getImageSrc,
|
||||||
sizes,
|
sizes,
|
||||||
outputDir
|
outputDir,
|
||||||
|
resizedDir
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue