|
|
|
@ -1,6 +1,10 @@
|
|
|
|
|
import slugify from 'slugify'
|
|
|
|
|
import { marked } from 'marked'
|
|
|
|
|
|
|
|
|
|
import * as fs from 'fs'
|
|
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
|
|
const basePath = path.join(path.resolve(), '/../../')
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* etaHelpers
|
|
|
|
@ -11,30 +15,32 @@ import * as fs from 'fs'
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* asset -
|
|
|
|
|
* asset - checks manifest.json for given path and return
|
|
|
|
|
* file path with id for cache busting
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {String} path
|
|
|
|
|
* @param {String} [prefix='/public']
|
|
|
|
|
* @param {String} publicPath
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function asset(path, prefix = '/public')
|
|
|
|
|
function asset(publicPath)
|
|
|
|
|
{
|
|
|
|
|
// getting basePath
|
|
|
|
|
const basePath = path
|
|
|
|
|
let result = publicPath
|
|
|
|
|
|
|
|
|
|
// path to mix-manifest
|
|
|
|
|
file = basePath + 'mix-manifest.json';
|
|
|
|
|
const file = basePath + 'mix-manifest.json'
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(file)) {
|
|
|
|
|
//const manifest = file_get_contents($file);
|
|
|
|
|
//const files = json_decode(manifest, true);
|
|
|
|
|
if (fs.existsSync(file)) {
|
|
|
|
|
|
|
|
|
|
//if (files[prefix + path]) {
|
|
|
|
|
// path = str_replace(prefix, '', files[prefix + path]);
|
|
|
|
|
//}
|
|
|
|
|
const manifest = fs.readFileSync(file)
|
|
|
|
|
const files = JSON.parse(manifest)
|
|
|
|
|
|
|
|
|
|
if (files[publicPath]) {
|
|
|
|
|
result = files[publicPath]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -98,4 +104,23 @@ async function injectStore(name) {
|
|
|
|
|
return store
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getting url for assets of directus api
|
|
|
|
|
*
|
|
|
|
|
* @param string string
|
|
|
|
|
* @param array array
|
|
|
|
|
* @return string
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function fileUrl(id, options = NULL)
|
|
|
|
|
{
|
|
|
|
|
$query = NULL;
|
|
|
|
|
|
|
|
|
|
if (options) {
|
|
|
|
|
$query = '?'.http_build_query($options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return process.ENV.DIRECTUS_API_URL + '/assets/' + id + $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { asset, templateClass, isHome, injectStore }
|