You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
979 B
53 lines
979 B
2 years ago
|
const path = require('path')
|
||
|
const fs = require('fs')
|
||
2 years ago
|
|
||
2 years ago
|
const Media = require('./../media.js')
|
||
2 years ago
|
|
||
|
/**
|
||
|
* asset - checks manifest.json for given path and return
|
||
|
* file path with id for cache busting
|
||
|
*
|
||
|
*
|
||
|
* @param {String} publicPath
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
function asset(staticPath)
|
||
|
{
|
||
|
// getting basePath
|
||
|
let result = staticPath
|
||
|
|
||
|
// path to mix-manifest
|
||
2 years ago
|
const file = path.join(path.resolve()) + 'mix-manifest.json'
|
||
2 years ago
|
|
||
|
if (fs.existsSync(file)) {
|
||
|
|
||
|
const manifest = fs.readFileSync(file)
|
||
|
const files = JSON.parse(manifest)
|
||
|
|
||
|
if (files[staticPath]) {
|
||
|
result = files[staticPath]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* asset - checks manifest.json for given path and return
|
||
|
* file path with id for cache busting
|
||
|
*
|
||
|
*
|
||
|
* @param {String} publicPath
|
||
|
*
|
||
|
*/
|
||
|
|
||
2 years ago
|
async function resize(src, sizes, options, done)
|
||
2 years ago
|
{
|
||
2 years ago
|
const media = new Media()
|
||
2 years ago
|
|
||
2 years ago
|
src = await media.resize(src, sizes, options)
|
||
|
done(null, src)
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
export { asset, resize }
|