diff --git a/packages/frontend/views/templates/page/blog.eta b/packages/frontend/views/templates/page/blog.eta index 61670ee..a046dc5 100644 --- a/packages/frontend/views/templates/page/blog.eta +++ b/packages/frontend/views/templates/page/blog.eta @@ -6,6 +6,7 @@ {{# if (posts.data && posts.data.length > 0) { }} {{# posts.data.forEach((post) => { }} {{ post.title }} + {{! it.marked.parse(post.teaser_content) }} {{# }) }} {{# } else { }} diff --git a/packages/server/_bootstrap.js b/packages/server/_bootstrap.js index 6438f32..1ce6e99 100644 --- a/packages/server/_bootstrap.js +++ b/packages/server/_bootstrap.js @@ -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: { diff --git a/packages/server/helpers/eta.js b/packages/server/helpers/eta.js index b887085..b0053be 100644 --- a/packages/server/helpers/eta.js +++ b/packages/server/helpers/eta.js @@ -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 } \ No newline at end of file +export { asset, templateClass, isHome, injectStore, mediaUrl } \ No newline at end of file