qwik-cms/libs/nunjucksConfig.js

31 lines
1.2 KiB
JavaScript

import njkMarkdown from 'nunjucks-markdown'
import marked from 'marked'
import { markedRenderer } from './markedRenderer.js'
import { utils } from './utils/utils.js'
export function nunjacksConfig(njk, express, Config) {
// Configure the nunjucks environment (HTML templating)
const njkEnv = njk.configure(
Config.contentDir,
{
autoescape: true, // Automatically escape HTML aka a '<' will become '&lt;'
watch: true, // Automatically reload all templates if they change on disk.
trimBlocks: true, // Remove trailing newlines from tags
lstripBlocks: true, // Automatically remove leading whitespace from tags
express: express // Use the express server. (Currently obsolete, I think.)
}
)
njkEnv.addGlobal('siteMap', entrypoint => utils.values.siteMap.render(entrypoint ? entrypoint : "/"))
// Configure marked (markdown parser)
marked.use({
gfm: true, // Use GitHub formatting?
renderer: markedRenderer // Use my own custom rendering for som tags
})
// Let nunjucks use markdown.
njkMarkdown.register(njkEnv, marked)
}