2021-08-09 17:44:53 +02:00
|
|
|
import njkMarkdown from 'nunjucks-markdown'
|
2023-08-02 14:28:26 +02:00
|
|
|
import { marked } from 'marked'
|
2021-08-09 17:44:53 +02:00
|
|
|
|
|
|
|
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 '<'
|
|
|
|
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?
|
2022-08-13 17:16:25 +02:00
|
|
|
renderer: markedRenderer, // Use my own custom rendering for som tags
|
2023-08-02 14:28:26 +02:00
|
|
|
mangle: false, // Remove deprecated warning
|
|
|
|
headerIds: false, // Remove deprecated warning
|
|
|
|
headerPrefix: false // Remove deprecated warning
|
2021-08-09 17:44:53 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// Let nunjucks use markdown.
|
|
|
|
njkMarkdown.register(njkEnv, marked)
|
|
|
|
}
|