develop
HerrHase 2 years ago
parent 01de6e1181
commit 86a7b7c790

@ -25,5 +25,6 @@
<link href="{{ http }}://{{ site.domain }}{{ page.path }}" rel="canonical">
<link rel="alternate" href="{{ http }}://{{ site.domain }}{{ page.path }}" hreflang="{{ site.language }}">
{% endif %}
{% endif %}
{% endmacro %}

@ -2,7 +2,7 @@
{% block main %}
<img src="{{ page.media.teaser.src | resize({ width: 100 }) }}" />
<img src="{{ page.fields.media.teaser.src | resize({ width: 100 }) }}" />
{{ page.content | safe }}
{% endblock %}

@ -1,5 +0,0 @@
{% extends('layout.njk') %}
{% block main %}
{{ page.content | safe }}
{% endblock %}

@ -1,6 +1,7 @@
const nunjucks = require('nunjucks')
const { minify } = require('html-minifier')
const fs = require('fs')
const assign = require('assign-deep')
const configStore = require('./../config.js')
const { asset, resize } = require('./helpers.js')
@ -17,10 +18,18 @@ const PageQuery = require('./../queries/pages.js')
*/
class Engine {
/**
*
*
* @param {string} views
* @param {object} site
* @param {object} options
*
*/
constructor(views, site, options) {
// merge options
this._options = Object.assign({}, {
// merge data
this._options = assign({}, {
autoescapes: true,
throwOnUndefined: true,
web: {
@ -29,6 +38,8 @@ class Engine {
}, options)
this.nunjucks = nunjucks.configure(views, this._options)
// add filter: resize
this.nunjucks.addFilter('resize', (...args) => {
const done = args.pop()
const options = args?.[2] ? {} : args[2]
@ -36,7 +47,7 @@ class Engine {
resize(args[0], args[1], options, done)
}, true)
// adding defaults for view, function and data = config.yml
// adding defaults for view, data from site.yml, functions and pageQuery
this._defaults = {
site: site,
asset: asset,
@ -53,12 +64,15 @@ class Engine {
*
*/
render(view, data, done) {
data = Object.assign({}, data, this._defaults)
// merge data
data = assign({}, data, this._defaults)
this.nunjucks.render(view, data, (error, response) => {
const options = configStore.get('options')
// if options minifyHtml is set, minify html
if (options.minifyHtml === true) {
response = minify(response, {
removeComments: true,

Loading…
Cancel
Save