adding mediaUrl from blade

develop
HerrHase 2 years ago
parent d579d0a40f
commit 8dfffd12f9

@ -6,6 +6,7 @@
{{# if (posts.data && posts.data.length > 0) { }}
{{# posts.data.forEach((post) => { }}
{{ post.title }}
<img src="{{ it.mediaUrl(post.teaser_media.id, { 'width': 500 }) }}" />
{{! it.marked.parse(post.teaser_content) }}
{{# }) }}
{{# } else { }}

@ -17,7 +17,7 @@ const server = fastify()
import * as Eta from 'eta'
import view from '@fastify/view'
import { asset, templateClass, isHome, injectStore } from './helpers/eta.js'
import { asset, templateClass, isHome, injectStore, mediaUrl } from './helpers/eta.js'
import { marked } from 'marked'
server.register(view, {
@ -34,7 +34,8 @@ server.register(view, {
templateClass: templateClass,
isHome: isHome,
injectStore: injectStore,
marked: marked
marked: marked,
mediaUrl: mediaUrl
},
options: {

@ -14,6 +14,7 @@ const basePath = path.join(path.resolve(), '/../../')
*
*/
/**
* asset - checks manifest.json for given path and return
* file path with id for cache busting
@ -82,7 +83,7 @@ function isHome(entity) {
/**
* injectStore
* injectStore -
*
*
* @param {String} name
@ -91,19 +92,21 @@ function isHome(entity) {
*/
async function injectStore(name) {
const path = './../stores/' + name + '.js'
const importPath = './../stores/' + name + '.js'
const filePath = basePath + 'packages/server/stores/' + name + '.js'
// if file
//if (!fs.existsSync(path)) {
//throw new Error(name + ' not exists!')
//}
// if class not exists, throw exception
if (!fs.existsSync(filePath)) {
throw new Error(name + ' not exists!')
}
const StoreClass = await import(path)
const StoreClass = await import(importPath)
const store = new StoreClass.default()
return store
}
/**
* getting url for assets of directus api
*
@ -112,15 +115,15 @@ async function injectStore(name) {
* @return string
*
*/
function fileUrl(id, options = NULL)
function mediaUrl(id, options = null)
{
$query = NULL;
let query = '';
if (options) {
$query = '?'.http_build_query($options);
query = '?' + new URLSearchParams(options).toString();
}
return process.ENV.DIRECTUS_API_URL + '/assets/' + id + $query;
return process.env.DIRECTUS_API_URL + '/assets/' + id + query;
}
export { asset, templateClass, isHome, injectStore }
export { asset, templateClass, isHome, injectStore, mediaUrl }
Loading…
Cancel
Save