import slugify from 'slugify' import { marked } from 'marked' import * as fs from 'fs' /** * etaHelpers * * collection for helpers to extend eta * * */ /** * asset - * * @param {String} path * @param {String} [prefix='/public'] * */ function asset(path, prefix = '/public') { // getting basePath const basePath = path // path to mix-manifest file = basePath + 'mix-manifest.json'; if (!fs.existsSync(file)) { //const manifest = file_get_contents($file); //const files = json_decode(manifest, true); //if (files[prefix + path]) { // path = str_replace(prefix, '', files[prefix + path]); //} } return path } /** * templateClass - parse template name to css-classname, * use prefix, default is "page" * * @param {Object} entity * @param {String} [prefix='page'] * @return {String} * */ function templateClass(entity, prefix = 'page') { if (entity.data && entity.data.template) { prefix += '-' + entity.data.template } return prefix } /** * isHome - check if entity is home, * checks for permalink * * @param {Object} entity * @return {Boolean} * */ function isHome(entity) { let result = false if (entity.data && entity.data.permalink && entity.data.permalink === "/") { result = true } return result } /** * injectStore * * * @param {String} name * @return {Object} * */ async function injectStore(name) { const path = './../stores/' + name + '.js' // if file //if (!fs.existsSync(path)) { //throw new Error(name + ' not exists!') //} const StoreClass = await import(path) const store = new StoreClass.default() return store } export { asset, templateClass, isHome, injectStore }