import nunjucks from 'nunjucks' ; import { get } from 'svelte/store' ; import { settingsStore } from '~/store' ; import type { Article , RenderTemplate } from './models' ; export class Renderer { constructor ( ) { nunjucks . configure ( { autoescape : false } ) ; } validate ( template ) { try { nunjucks . renderString ( template , { } ) ; return true ; } catch ( error ) { return false ; } } render ( entry , isNew = true ) { const { metadata , highlights } = entry ; const context = { is_new_article : isNew , ... metadata , highlights : highlights . map ( ( a ) => ( { ... a } ) ) } ; const template = get ( settingsStore ) . template ; const content = nunjucks . renderString ( template , context ) ; return content ; } }